0

In PHP, how would I parse the following query string to get the entire variable "url" which should contain everything after it?

http://www.mydomain.com/?c=log&m=index&url=https://www.facebook.com/logout.php?next=http%3A%2F%2Fwww.anotherdomain.com&access_token=AAACPpB5pr5gBAJLFZBGaU6SM7UMlGQob7QUBf3aI0DIHrHWtcTGHirS0UrwwDDZBEiIQHeWfkOVCFbEXrFt6TdVlbPrXmV6xyPDI9pPQZDZD

$_GET['url'] drops everything after 'www.anotherdomain.com' because it encounters another '&'.

The problem is that 'url' is provided by Facebook. If I urlencode the entire string, it becomes invalid. How would I parse 'url' to programmatically urlencode only the piece that needs to be changed?

0

2 Answers 2

2

try something like this

 $link = "http://www.mydomain.com/?c=log&m=index&url=";
 $link .= rawurlencode('https://www.facebook.com/logout.php?next=http%3A%2F%2Fwww.anotherdomain.com');
 $link .= '&access_token=AAACPpB5pr5gBAJLFZBGaU6SM7UMlGQob7QUBf3aI0DIHrHWtcTGHirS0UrwwDDZBEiIQHeWfkOVCFbEXrFt6TdVlbPrXmV6xyPDI9pPQZDZD';

to retrireve the data use

  $url_get = rawurldecode($_GET['url']); 
Sign up to request clarification or add additional context in comments.

2 Comments

Half the point of $_GET is that it decodes the data for you. So you don't need to decode it manually.
Your first chunk of code changes the name of the variable half way through … then changes it back.
2

The url should be urlencoded before being passed, otherwise it is an invalid query string parameter.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.