Page 1 of 1

capturing redirect query strings

Posted: Thu Nov 27, 2003 9:51 am
by kendall
Hey ppl,

The following code redirects a user to a login form if a session isnt present

Code: Select all

if(!session_is_registered('User')){
	$query = $_SERVER['QUERY_STRING'];
	header('Location: login_form.php?redirect=post_message_form.php?'.$query);
}
in the login form page

Code: Select all

if($_REQUEST['redirect'])
	$redirect = $_REQUEST['redirect'];
else $redirect = $PHP_SELF.'?'.$_SERVER['QUERY_STRING'];
how ever in running a request with a paramters script.php?redirect=page.php?param=1&param=2&param=3
$redirect = page.php?param=1
so what happens to the rest?

how do you guys handle redirecting situations?

the thing is i want the person to be able to go back to the way he was before he had to go log in and stuff after he logs in

Kendall

Posted: Thu Nov 27, 2003 10:32 am
by m3mn0n
The first GET variable has to use a ? before the variable name. All the others after it must use &.

Posted: Thu Nov 27, 2003 10:50 am
by kendall
Sami,

uhhm...so what does that mean? it cant see pass the '&'?

Kendall

Posted: Thu Nov 27, 2003 10:59 am
by microthick
You could probably use urlencode() to encode you redirect string then use that as a url parameter. Then, $_GET that string and urldecode() it.

Re: capturing redirect query strings

Posted: Thu Nov 27, 2003 11:21 am
by m3mn0n
I would do this

Send a get variable to the page, eg.

?error=true

and then also send

&errortype=nosession

And then within a section of your page, add a series of header's that will redirect a user to a specific page based on if the error exist and which type of error it is.

eg.

Code: Select all

<?php
if ($_GET['error'] == true)
{
 switch ($_GET['errortype'])
  default:
    header ("Locaiton: error1.php");
  break;
  case 'nosession':
    header ("Locaiton: error1.php");
  break;
  case 'hackattempt':
    header ("Locaiton: error2.php");
  break;
  case 'missingvariable':
    header ("Locaiton: error3.php");
  break;
 }
}
?>

Posted: Thu Nov 27, 2003 12:39 pm
by kendall
Yes,

microthick...ok ill try that

sami...yes but...why is it that if i have

Code: Select all

$redirect = 'script.php?param=1&param=2'; 
header('Location: script2.php?redirect='.$redirect);
i will get
$redirect = script.php?param=1
and not
$redirect = script.php?param=1&param=2
?
Kendall

Posted: Thu Nov 27, 2003 1:30 pm
by Weirdan
you need:

Code: Select all

$redirect = urlencode('script.php?param=1&param=2'); 
header('Location: script2.php?redirect='.$redirect);
then:

Code: Select all

$redirect=urldecode($_REQUEST["redirect"]);