Reputation: 1
i'm having some issues with PHP sessions. I'm pretty new to PHP so my apologies if i'm being completely stupid.
I have a login.php file that once the user name and password has been checked etc it has the following code:
if($pass === $row2['PSWD']){
session_start();
$_SESSION['test']="hello";
mysql_close($con);
header("Location: page.php");
}else{
die('Wrong password');
}
then on page.php I have the following at the very top, about the tag:
<?php
session_start();
session_register(); //just in case...(should not be needed)
echo "Result:".$_SESSION['test'];
?>
And all I get at the top of the page is "Result:"
Any ideas? As from everything i've been reading it should be as simple as this?
Thanks in advance!
EDIT:
My error logs are showing:
Warning: session_start() [function.session-start]: open(/var/php_sessions/sess_b91f8653bcee6ef7c1e13ae8844f00da, O_RDWR) failed: No such file or directory (2) in /hermes/bosweb/web261/b2617/ipg.craigfisk/webtest/login.php on line 28
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /hermes/bosweb/web261/b2617/ipg.craigfisk/webtest/login.php:28) in /hermes/bosweb/web261/b2617/ipg.craigfisk/webtest/login.php on line 28
Warning: Cannot modify header information - headers already sent by (output started at /hermes/bosweb/web261/b2617/ipg.craigfisk/webtest/login.php:28) in /hermes/bosweb/web261/b2617/ipg.craigfisk/webtest/login.php on line 31
Warning: Unknown: open(/var/php_sessions/sess_b91f8653bcee6ef7c1e13ae8844f00da, O_RDWR) failed: No such file or directory (2) in Unknown on line 0
Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/php_sessions) in Unknown on line 0
Upvotes: 0
Views: 956
Reputation: 1313
You need to put exit();
after your header redirection, otherwise you have just loaded two pages of content into 1 page.
source: https://stackoverflow.com/a/3023479/710827
Upvotes: 1