2

I have this URL:

http://www.example.com/get_url.php?ID=100&Link=http://www.test.com/page.php?l=1&m=7

When I print $_GET['Link'], I see only http://www.test.com/page.php?l=1.

Where is &m=7?

2
  • 2
    why don't you try print_r($_GET); Commented Jan 24, 2011 at 9:34
  • 1
    &m=7 is part of the "main" URL http://www.xxx.com/get_url.php... Commented Jan 24, 2011 at 9:34

3 Answers 3

8

If you want to pass an url as a GET parameter, you'll have to URL-encode it.

The problem is, the server sees & as ending the Link parameter. This means you're actually getting:

$_GET['ID'] = '100';
$_GET['Link'] = 'http://www.test.com/page.php?l=1';
$_GET['m'] = '7';

What you want to do is use urlencode. Example:

$link = 'http://sample.com/hello?a=5&b=6&d=7';
$address = 'http://site.com/do_stuff.php?link='.urlencode($link)

External references:

Sign up to request clarification or add additional context in comments.

3 Comments

Great answer. Let me just quickly add that when you retrieve the value, you'll want to use urldecode(): $link = urldecode($_GET['Link']; :)
Actually you don't need to urldecode; that's automatically handled for you by PHP.
Is it? That's nice, thanks for correcting me then, I wasn't aware of this one.
1

It's a separate value. If you pass it this way, the GET values are:

ID=100
Link=http://www.test.com/page.php?l=1
m=7

The & character separates values passed by GET.

In order to pass the entire thing, you need to encode it properly (see Sebastian's answer).

Comments

-1

(see sebastian's answer).The server sees & as the ending parameter so u won't get the values after &.If u want to get the entire thing u need to encode the entire link using "function urlencode()" before passing the parameters

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.