Skip to main content
gamedev.net
🔒 Locked

[web] [PHP] parse URL from URL variable

Started by supagu Jan 6, 2007 at 9:30 PM 5 replies 1.4k views
Original Post
supagu
supagu
okay i've got a website where i need the user to login, the login page takes an optional string, an URL to redirect the user to once they have loged in. eg. www.test.com/login.php?redirect=www.test.com/somepage.php this has been working alright for me, but now i need to pass some vars to somepage.php and this doesnt work well in the browser: www.test.com/login.php?redirect=www.test.com/somepage.php?somevar=3&somevar2=2 i tried putting " " marks around the redirect string like so: www.test.com/login.php?redirect="www.test.com/somepage.php?somevar=3&somevar2=2" but this doesnt work either. any ideas on another solution?
Colin Jeanne
Colin Jeanne
The URL looks fine to me. What do you mean by "doesnt work"? The PHP variable $_GET['redirect'] does not equal "www.test.com/somepage.php"?
supagu
supagu
redirect should be:
www.test.com/somepage.php?somevar=3&somevar2=2

but i get:
www.test.com/somepage.php?somevar=3

Narcis
Narcis
Its because the & makes it a new variable.

Make the url:
page.com/somepage.php?redirect=www.webpage.com/somepage.php?var=3+var=4

And str_replace:
$url = str_replace("+", "&", $_GET['redirect']);
header("location: " . $url); // redirect

The URL should be full and correct now ($url beeing the correct one).

Edit: Even better would be to replace the ? also, just as a precaution...
Mushu
Mushu
Likewise, you'll need to use urldecode() on the string that you retrieve from $_GET.
markr
markr
No, you shouldn't need urldecode() on what comes in from $_GET (or $_POST etc,).

PHP automatically decodes query strings and form-encoded fields.

Mark

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.