PHP sessions question
Posted: Sat Oct 03, 2009 10:59 am
I've only started to use php sessions but I keep getting an error. Can someone tell me why my code below doesn't work? Firefox says my problem is in line 21 (line 18 here) which is header ("Location: http://localhost/labs/php_sessions/page2.php"); but how can that be?
I simplified the markup so it's easier to see:
And just in case, here's the actual error message
I simplified the markup so it's easier to see:
Code: Select all
<?php
session_start();
if($_POST['pass'] == '123'){
$_SESSION['login'] = true;
}
else {
$_SESSION['login'] = false;
}
?>
<html>
<head></head>
<body>
<?php
if($_SESSION['login']){
header ("Location: http://localhost/labs/php_sessions/page2.php");
exit();
}
else {
?>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
<input name="pass" type="password" /><input name="" type="submit" />
</form>
<?php
}
?>
</body>
</html>
And just in case, here's the actual error message
Code: Select all
Warning: Cannot modify header information - headers already sent by (output started at D:\xampp\htdocs\labs\php_sessions\index.php:19) in D:\xampp\htdocs\labs\php_sessions\index.php on line 21