etsted Posted March 7, 2014 Share Posted March 7, 2014 all of my php pages works fine localy on my computer whit session, but wheni upload them to a server they dont work. I search a little and read that my sessions might get lost, i didnt understand what that meant. Can somebody tell me how i can fix that, so that i can upload my pages to a server whitout a session problem? And give examples. Link to comment Share on other sites More sharing options...
justsomeguy Posted March 7, 2014 Share Posted March 7, 2014 I've never heard of a problem like that. What exactly are you seeing happen? What does "don't work" mean? Link to comment Share on other sites More sharing options...
etsted Posted March 7, 2014 Author Share Posted March 7, 2014 (edited) when i run my webpage localy it works fine, my sessions works. But when i upload them to a remote server, the sessions doesnt store the user information, so it keeps on logging me out. Edited March 7, 2014 by etsted Link to comment Share on other sites More sharing options...
davej Posted March 7, 2014 Share Posted March 7, 2014 Well, is the remote server running an older version of Php? Link to comment Share on other sites More sharing options...
etsted Posted March 7, 2014 Author Share Posted March 7, 2014 5.3 Link to comment Share on other sites More sharing options...
etsted Posted March 7, 2014 Author Share Posted March 7, 2014 could the problem be that the session expires to fast? If so how do i extend it? Link to comment Share on other sites More sharing options...
justsomeguy Posted March 7, 2014 Share Posted March 7, 2014 The default session expiration time is 24 minutes, you can set that in the php.ini file. I would look elsewhere though, make sure that PHP is either displaying or logging all error messages to make sure you're not missing something. Maybe it can't start the session because headers have already been sent for some reason, for example. Link to comment Share on other sites More sharing options...
davej Posted March 7, 2014 Share Posted March 7, 2014 5.3 on both? Link to comment Share on other sites More sharing options...
etsted Posted March 7, 2014 Author Share Posted March 7, 2014 yes 5.3. I tried an error logger, but nothing shows up. Link to comment Share on other sites More sharing options...
etsted Posted March 7, 2014 Author Share Posted March 7, 2014 i have tried to logg all the errors, but nothing shows up. I have read somewhere that something might be wrong whit the time settings, but i dont know. If you like read this: http://strangerzlog.blogspot.it/2012/04/php-redirect-losing-sessions-on.html Link to comment Share on other sites More sharing options...
justsomeguy Posted March 7, 2014 Share Posted March 7, 2014 Well, feel free to check the time on the server then. Link to comment Share on other sites More sharing options...
davej Posted March 8, 2014 Share Posted March 8, 2014 My first thought would be to create a very simple session-test page. Link to comment Share on other sites More sharing options...
etsted Posted March 8, 2014 Author Share Posted March 8, 2014 (edited) i made another session test file and it worked, but this doesnt seem to work, it doesnt store the session. can anyone tell me what wrong? <!DOCTYPE html><?php session_start();?> <html> <head> <meta charset="UTF-8" /> <link href='style/style.css' rel='stylesheet' type="text/css" /> <title>Login</title> <meta name='description' content='login to itsnature' /> <meta name='keywords' content='login' /> </head> <body> <h1>Login</h1> <?php require_once "connect.php"; // login form $login = "<form action='login.php' method='POST' name='login1' class='forgotpass'> <input type='text' name='username' placeholder='Username' /> <br /> <input type='password' name='password' placeholder='Password' /> <input type='submit' name='submit' value='Login' /> | <a href='register.php'>Register</a> </form>"; if(isset($_SESSION['username'])) { $username = $_SESSION['username']; } // sets a navigator if(isset($username)) { include "navigator/navigator_login.php"; echo "hei"; } else { include "navigator/navigator.php"; echo "hei feil"; } if(isset($username)) { echo "<p>Welcome $username.</p> <br />"; } else { if(isset($_POST['username']) && isset($_POST['password'])) { $username = mysqli_real_escape_string($con, $_POST['username']); $password = mysqli_real_escape_string($con, $_POST['password']); } if(isset($username) && isset($password)) { $password = md5($password); $query = mysqli_query($con ,"SELECT * FROM users WHERE username='$username' && password='$password'") or die(mysql_error()); $numrows = mysqli_num_rows($query); if($numrows != 0) { $_SESSION['username']=$username; echo "<p>You have been logged in.</p> <br />"; } else { echo "<p>Wrong password or username.</p>$login"; } } else { echo "<p>You must register an account in order to login.</p>$login"; } } mysqli_close($con); ?> </body> </html> Edited March 8, 2014 by etsted Link to comment Share on other sites More sharing options...
davej Posted March 8, 2014 Share Posted March 8, 2014 Put session_start before the DOCTYPE. Link to comment Share on other sites More sharing options...
etsted Posted March 8, 2014 Author Share Posted March 8, 2014 It worked, thank you Link to comment Share on other sites More sharing options...
birbal Posted March 8, 2014 Share Posted March 8, 2014 When you develop always make sure to enable 'error_display' and 'error_reporting' to show all kind of error in php.ini . It tells you exactly why and where it is going wrong without need of guessing. 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