Share url along with query is not working

I have an educational website. When a student retrieves their result via URL, I’ve included an option to automatically add the result to their LinkedIn credentials. The code successfully retrieves all results except those queried from the URL. Below is the code snippet:

 // Function to get the current URL
            function getCurrentURL() {
                $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http";
                $host = $_SERVER['HTTP_HOST'];
                $uri = $_SERVER['REQUEST_URI'];
                $queryString = isset($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : '';
                return $protocol . "://" . $host . $uri . $queryString;
            }

            $currentUrl = getCurrentURL();

            // Generating LinkedIn URL
            $linkedinUrl = "https://www.linkedin.com/profile/add?startTask=" . urlencode($Learner_Name) .
                            "&name=" . urlencode($Qualification_Name) .
                            "&organizationName=KNOWER%20INTERNATIONAL" . // Updated organization name
                            "&issueYear=" . date("Y", strtotime($Date_Awarded)) .
                            "&issueMonth=" . date("m", strtotime($Date_Awarded)) .
                            "&expirationYear=" . date("Y", strtotime($Date_Expiry)) .
                            "&expirationMonth=" . date("m", strtotime($Date_Expiry)) .
                            "&certUrl=" . $currentUrl . // Updated certificate URL to current page URL
                            "&certId=" . urlencode($Certificate_No); // Updated certificate ID
        }
    }

Can anyone please identify where is the problem. Thank You

It would be helpful if you posted an example and pointed out what is wrong with it.

I recommend that you build the query string key/values in an array, then use php’s http_build_query() to produce the query string part of the URL, since it urlencodes all the values for you.

I could be wrong, but I think you will have a problem with adding LinkedIn credentials as companies are pretty tight in protecting their user’s data unless you’re just displaying it. Though I would imagine you will have to get permission to even display it just like you have to accept cookies on websites.

  • What steps have you already tried to share the URL with the query? Are you using a specific button, feature, or method?
Sponsor our Newsletter | Privacy Policy | Terms of Service