Go Back   SitePoint Forums > Forum Index > Program Your Site > PHP
Newsletter FAQ Members List Calendar Mark Forums Read

New to SitePoint Forums? Register here for free!

SitePoint Sponsor
 
Reply
 
Thread Tools Display Modes
Old Nov 9, 2006, 09:42   #1
WeakestLink
SitePoint Zealot
 
Join Date: Jul 2006
Location: Closer than you think
Posts: 149
Redirect and $_SERVER['Request_URI']

I am trying to allow a redirect after logging in which is great when I have one variable.

On Page1.php I have

PHP Code:

if ($_SESSION['loggedin'] != yes)

{
header("Location:LogIn.php?r=".$_SERVER['REQUEST_URI']);
}
On the Login.php Page
PHP Code:

...

if (
$SuccessfulLogin && isset($_GET['r']))
{
header("Location:".$_GET['r'])
}
Ignore any typos. The Redirect Works Great except when more the one Variable is in the URL

ex. Page1.php?val1=1&val2=1

It will redirect me to Page1.php?val=1

Obvious when I am redirected to the login it's not copying correctly

Login.php?r=/page1.php?val1=Page1.php?val1=1&val2=1

$_GET['r'] is equal to /page1.php?val1=Page1.php?val1 The & is starting another Variable.

Any suggestions on this?
WeakestLink is offline   Reply With Quote
Old Nov 9, 2006, 09:46   #2
php_daemon
✯✯✯
silver trophybronze trophy
 
php_daemon's Avatar
 
Join Date: Mar 2006
Posts: 5,009
PHP Code:

if ($_SESSION['loggedin'] != yes)

{
header("Location:LogIn.php?r=".urlencode($_SERVER['REQUEST_URI']));
}
php_daemon is online now   Reply With Quote
Old Nov 9, 2006, 12:40   #3
clamcrusher
SitePoint Wizard
silver trophy
 
Join Date: Mar 2006
Posts: 6,132
dont forget to call exit(); after sending a redirect header unless you want your script to continue executing.
clamcrusher is offline   Reply With Quote
Old Nov 9, 2006, 15:02   #4
stereofrog
SitePoint Wizard
 
stereofrog's Avatar
 
Join Date: Apr 2004
Location: germany
Posts: 4,321
Quote:
Originally Posted by WeakestLink
header("Location:".$_GET['r'])
This code is questionable for two reasons.

Redirect to a relative url is a violation of the HTTP standard which states you must use only absolute urls (starting with protocol and host name).

Direct ouputting unfiltered user input is always a security concern. You should at least validate request parameter to make sure it is really what you expect it to be.
stereofrog is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread | Next Thread »

Thread Tools
Display Modes

 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Sponsored Links
 
Forum Jump


All times are GMT -7. The time now is 21:43.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright 1998-2009, SitePoint Pty Ltd. All Rights Reserved