Solved

$_GET URL variable not working

Posted on 2006-06-15
7
375 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
  • 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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

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 125 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

810 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