headers problem

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

Post Reply
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

headers problem

Post by a94060 »

WEll i have this peice of code here in my script:

Code: Select all

<?PHP
$user = $_POST['you'];
$pass = $_POST['me'];
if(($user == 'XXX') && ($pass == 'XXX')) {
$_SESSION['in'] == TRUE;
header(Location: ../admin/tabview.php ); //if the username and pass match go to the tabview page
}
else{
header(Location: ../admin ); //if not send back to login page
}
?>
im not sure what is wrong,i get an error about the : that is in there.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

1-) You can redirect users, by sending out a location http://www.php.net/header. As you can read in the manual this function accepts a string. Eg:

Code: Select all

header('Location: http://example.com');
2-) Before you do the redirection, you should call http://www.php.net/session_write_close in order to make sure that the session data is stored...

3-) You should not use relative URLs for redirection.. There are browsers that don't handle them well...
User avatar
$phpNut
Forum Commoner
Posts: 40
Joined: Tue May 09, 2006 5:13 pm

Post by $phpNut »

You need to put single or double quotes in your header()'s.
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post by a94060 »

-) Before you do the redirection, you should call http://www.php.net/session_write_close in order to make sure that the session data is stored...

Say i do a session like this

Code: Select all

$_SESSION['in'] = 'yes';
will that value go onto to other pages that are within the site?for example,can i call it on another page like

Code: Select all

if($_SESSION['in'] == 'yes') {
echo 'This is right';
}
that will work?
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

You'll need to start the session with session_start(), but otherwise, that's correct.
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post by a94060 »

ok,so i will need to make sure on everypage i call session_start()
Post Reply