rubberchicken
rubberchicken

Reputation: 1322

$_SERVER['REQUEST_URI'] and $_GET

How do I pass a destination variable in a URL which contains OTHER variables from last page?

Basically, when I'm on index.php?year=2014&month=3 and when i click edit.php link I want it to remember the (index.php?year=2014&month=3) so it returns me back there after editing... I placed this in $destination but its conflicting with my URL variables...

SERVER['REQUEST_URI'] returns: index.php?year=2014&month=3

my php code:

$destination = $_SERVER['REQUEST_URI'];
$edit_url = "edit.php?id=$id&proj=$proj&t=$t&year=$year&month=$month&day=$day&destination=$destination";

when I click the edit link: http://www.site.com/edit.php?id=5&proj=3&t=1&year=2014&month=4&day=13&destination=/index.php?year=2014&month=3

once it takes me to edit.php I noticed its not capturing the hidden input &month=3 in source it shows:

<input type="hidden" name="destination" value="/index.php?year=2014">

it should be showing:

<input type="hidden" name="destination" value="/index.php?year=2014&month=3">

I know it's because of the & sign which is causing this...is it possible to make url.php?blah=1&destination=/page.php?var=1&var=2 ??? If so, can someone tell me how?

Upvotes: 2

Views: 1362

Answers (1)

Tyler Carter
Tyler Carter

Reputation: 61577

You should use urlencode() to encode $destination before you add it to the URL.

Basically, you are adding a value to a URL with a & in it which is a special character used for other purposes in a URL. The server is seeing this character and is cutting the value short. By encoding it, you should get the correct value.

You can use urldecode() to return the value back to normal later on.

Upvotes: 7

Related Questions