PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
kendall
Forum Regular
Posts: 852 Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:
Post
by kendall » Thu Nov 27, 2003 9:51 am
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¶m=2¶m=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
m3mn0n
PHP Evangelist
Posts: 3548 Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada
Post
by m3mn0n » Thu Nov 27, 2003 10:32 am
The first GET variable has to use a ? before the variable name. All the others after it must use &.
kendall
Forum Regular
Posts: 852 Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:
Post
by kendall » Thu Nov 27, 2003 10:50 am
Sami,
uhhm...so what does that mean? it cant see pass the '&'?
Kendall
microthick
Forum Regular
Posts: 543 Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC
Post
by microthick » Thu Nov 27, 2003 10:59 am
You could probably use urlencode() to encode you redirect string then use that as a url parameter. Then, $_GET that string and urldecode() it.
m3mn0n
PHP Evangelist
Posts: 3548 Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada
Post
by m3mn0n » Thu Nov 27, 2003 11:21 am
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;
}
}
?>
kendall
Forum Regular
Posts: 852 Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:
Post
by kendall » Thu Nov 27, 2003 12:39 pm
Yes,
microthick...ok ill try that
sami...yes but...why is it that if i have
Code: Select all
$redirect = 'script.php?param=1¶m=2';
header('Location: script2.php?redirect='.$redirect);
i will get
$redirect = script.php?param=1
and not
$redirect = script.php?param=1¶m=2
?
Kendall
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Thu Nov 27, 2003 1:30 pm
you need:
Code: Select all
$redirect = urlencode('script.php?param=1¶m=2');
header('Location: script2.php?redirect='.$redirect);
then:
Code: Select all
$redirect=urldecode($_REQUEST["redirect"]);