Solved

$_GET URL variable not working

Posted on 2006-06-15
7
394 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
WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

 

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

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

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…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
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 …

623 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