aarontbarksdale Posted May 28, 2013 Share Posted May 28, 2013 (edited) I have a log in script: <?phpsession_start();require ('connect.php'); // Connect to server and select databse.mysql_connect("$host", "$login", "$pass")or die("cannot connect");mysql_select_db("$db_name")or die("cannot select DB"); // Define $myusername and $mypassword$myusername=$_POST['username'];$mypassword=$_POST['password']; // To protect MySQL injection (more detail about MySQL injection)$myusername = stripslashes($myusername);$mypassword = stripslashes($mypassword);$myusername = mysql_real_escape_string($myusername);$mypassword = mysql_real_escape_string($mypassword);$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";$result=mysql_query($sql); // Mysql_num_row is counting table row$count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 rowif($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" $_SESSION["myusername"] = $myusername; $_SESSION["mypassword"] = $mypassword; header("location:/login/login_success.php");}else { echo "Wrong Username or Password";}?> When I log in for the FIRST time, it "logs in" but not correctly. It doesn't show user-specific information until I log out then log back in and it works. It does something similar when I have it go to a Report page. I have to "Go Back" and then click the Report again before it shows the correct information. Any suggestions why it's doing that??? Edited May 28, 2013 by aarontbarksdale Link to comment Share on other sites More sharing options...
justsomeguy Posted May 28, 2013 Share Posted May 28, 2013 Add a call to session_write_close before you send the header to redirect: http://www.php.net/manual/en/function.session-write-close.php Link to comment Share on other sites More sharing options...
aarontbarksdale Posted May 28, 2013 Author Share Posted May 28, 2013 So, I should put session_write_close BEFORE the redirect? Or after? And what about for the form data? Link to comment Share on other sites More sharing options...
aarontbarksdale Posted May 28, 2013 Author Share Posted May 28, 2013 When I click to generate the report for the first time after logging on, it is supposed to pull from the database to get the start date...however, it defaults to 12/31/1969, I go back, then "generate the report" again and it's correct. Just trying to eliminate the need to go back and/or logout then log in again. Link to comment Share on other sites More sharing options...
justsomeguy Posted May 28, 2013 Share Posted May 28, 2013 You should write and close the session after setting all of the data, and before redirecting. A 12/31/1969 date indicates that you have a timestamp with a value of 0. The Unix timestamp is the number of seconds since 1/1/70, so 12/31/1969 11:59:59 is the date when the timestamp has a value of 0 or is missing. It's hard to suggest what might be wrong without seeing the code, but it's showing that date because of a missing timestamp. Link to comment Share on other sites More sharing options...
aarontbarksdale Posted May 28, 2013 Author Share Posted May 28, 2013 But then when you go back by any way, whether hitting the BACK button or a link then generating the report again fixes it. Why? Link to comment Share on other sites More sharing options...
justsomeguy Posted May 28, 2013 Share Posted May 28, 2013 Again, I can't speculate about what it's doing without actually seeing the code. It could be anything. I can write code to do that, but I can't guess why your code is doing it. Maybe you're setting a value in the session after you try to use it for the first time. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now