Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

$_GET URL variable not working

Posted on 2006-06-15
7
Medium Priority
?
400 Views
Last Modified: 2008-02-01
Greetings...

I've got a weird issue here.  I'm passing a URL in a variable called, URL to another page to be redirected.  For some reason the $_GET function isn't picking up all of the variables.  Here is the URL that is being passed:

URL=http://www.mydomain.com/asp/detail.asp?1=&p=297&o=1

Now here is my code to grab the variable:

$redirect = $_GET['URL'];
header ('Location:'.$redirect);

When you echo $redirect all you get back is:
http://www.mydomain.com/asp/detail.asp?1=

It seems to stop right after the = sign.  Any ideas?  I'm also passing some other variables such as an ID and I can get that just fine.
0
Comment
Question by:cwilkey
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 33

Expert Comment

by:snoyes_jw
ID: 16912960
You'll need to urlencode the value for URL before you pass it on to this page.  Otherwise, how does PHP know that those variables belong with the URL variable, and not just a part of the rest of the variables?
0
 

Author Comment

by:cwilkey
ID: 16912990
Yikes...so here in lies the problem.  Not every URL passed will have variables in them.
0
 
LVL 7

Expert Comment

by:aib_42
ID: 16913046
What if you also wanted to pass p=296?

something.php?URL=http://www.mydomain.com/asp/detail.asp?1=&p=297&o=1&p=296 ? Does this look OK to you? Where does the URL end and p start?

You cannot have '&' or other special URL characters inside a variable being passed via GET.
You can make a simple form with
<form method="get" action="something.php"><input type="hidden" name="URL" value="http://www.mydomain.com/asp/detail.asp?1=&p=297&o=1"><input type="submit"></form>
and see how the browser passes the URL to the PHP script.

It will be URL-encoded, as per urlencode(). So if you're manually passing the URL, you should URL-encode it as well.

$foo = urlencode("http://www.mydomain.com/asp/detail.asp?1=&p=297&o=1");
$link = "something.php?URL=$foo&p=296";
echo "<a href=\"$link\">...</a>";

will yield a URL like:

something.php?URL=http%3A%2F%2Fwww.mydomain.com%2Fasp%2Fdetail.asp%3F1%3D%26p%3D297%26o%3D1&p=296

And this time you will be able to use $_GET['URL'] properly.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:cwilkey
ID: 16913132
Creating a form will isn't an option.  I've created a banner management system that passes it's URL to a page so the database can record it's impression/clicks.  It then redirect to the URL based on the domain passed.

So, I tried:

$redirect = urlencode($_GET['URL']);
header ('Location:'.$redirect);

And I got: http%3A%2F%2Fwww.spiritlakehomes.com%2Fasp%2Fdetail.asp%3F1%3D

0
 
LVL 33

Accepted Solution

by:
snoyes_jw earned 500 total points
ID: 16913149
er, no.  You'll need to call urlencode on the page before.  The one that generates URL in the first place.
0
 

Author Comment

by:cwilkey
ID: 16913188
That's it.  That did it.  Thank you sir...or mam!
0
 
LVL 33

Expert Comment

by:snoyes_jw
ID: 16913253
You're welcome.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question