skunk a
skunk a

Reputation: 245

Getting URL including parameters passed in an URL as a parameter

In my website I have a mechanism when your session has expired I save the current location and redirect you to the login page to log on, so the url is as follow

localhost/mytest/admin/login-admin.html?current=localhost/mytest/admin/manage-customer.php?action=update&id_annonceur=2

Once you are logged in, I redirect the user to the url stored in the current parameter. The problem is when I use the following code

if(isset($_GET['current']))
    header('Location: http://'.$_GET['current']);
else
    header('Location: ../admin/dashboard.php');

I get the URL without the parameters included in the URL

http://localhost/mytest/admin/gestion-annonceur.php?action

Is there a way to retrieve the complete url including parameters?

Upvotes: 0

Views: 40

Answers (1)

Barmar
Barmar

Reputation: 781058

Make sure you URL-encode the original URL when you put it into the current parameter. It should be:

localhost/mytest/admin/login-admin.html?current=localhost%2Fmytest%2Fadmin%2Fmanage-customer.php%3Faction%3Dupdate%26id_annonceur%3D2

Use the urlencode() PHP function to generate this encoding.

Upvotes: 3

Related Questions