Are you starting the session in page2 ? If your answer is yes, then you need to show us your code. If your answer is no, then start the session ! :)
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
are you putting session_start() at the top of all the pages that require the session?
You beat me by few seconds :P
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
I don't see anything wrong with the code apart from this line. if(!$_POST['username'] | !$_POST['pass']) {
It should have been if(!$_POST['username'] || !$_POST['pass']) { . Thats just a syntax error. The code isn't long ! lol.. it has just 80+ lines. Anyway, Check if its entering the else { $_SESSION['views'] part. If its entering the else part, remove the meta tag and try again..
Edit: And btw, is wrong. What is "!" doing there ?
Edit 2: And, you are not printing $_SESSION['views'] in page 2 :)
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
I have modified your code to test it and it works. Here's the code. Modify it again to meet your requirements.
<?php //login1.php
session_start();
ob_start();
?>
<?php
//if login form is submitted
if(1==2) {
die('incorrect password,please try again.');
}
else
//if login is ok then direct them to options page
{
$_SESSION['views'] = 1;
header("Location:option1.php");
ob_flush();
?>
<META HTTP-EQUIV="Refresh" CONTENT="0; URL=option1.php">
<?php
}
?>
And here is option1.php
<?php
session_start();
ob_start();
if(isset($_SESSION['views'])) {
$_SESSION['views']=$_SESSION['views']+1;
echo $_SESSION['views'];
}
else
{
//header("Location:message.php");
echo "session not set"."</br>";
print_r($_SESSION);
}
?>
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
php and apache versions doesn't matter.
Check the loop, I have added if(1==2) which will always fail. Replace it with your validation part.
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
Replace if(1==2) with
if(!$_POST['username'] || !$_POST['pass']) {
die('You did not fill all the fields.');
}
and leave the else part as it is.
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
hmm..Your above script should definitely work.. Check your php.ini file for session.
Check for these lines and if its commented, uncomment it.
session.save_handler = files
session.use_cookies = 1 .
If this doesn't work, then I can't do much about it.
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356