Page 1 of 1
session getting lost
Posted: Fri Mar 07, 2014 3:00 pm
by etsted
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.
Re: session getting lost
Posted: Fri Mar 07, 2014 3:06 pm
by Celauran
etsted wrote:but wheni upload them to a server they dont work
Can you elaborate on that?
Re: session getting lost
Posted: Fri Mar 07, 2014 3:37 pm
by etsted
the sessions doesnt store user information, so the webpage keeps on logging me out. But it doesnt do that if i run the webpage localy.
Re: session getting lost
Posted: Fri Mar 07, 2014 3:42 pm
by Celauran
Have you inspected the $_SESSION array? Are any errors being displayed (or logged)? Is error reporting on?
Re: session getting lost
Posted: Fri Mar 07, 2014 4:04 pm
by etsted
what u mean? it works localy when i run the script on my pc no errors.
Re: session getting lost
Posted: Fri Mar 07, 2014 4:20 pm
by Celauran
So we're back to "it doesn't work" with no additional detail. We can't help you if you won't even answer our questions. Got nothing to work with here.
Re: session getting lost
Posted: Fri Mar 07, 2014 4:52 pm
by etsted
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 ... ns-on.html
Re: session getting lost
Posted: Fri Mar 07, 2014 4:56 pm
by hybris
Are you using header(location: ...) to redirect? If so dont use the full url
http://www.mysite.com/secure page but local way like ../securepage.php
Atleast that worked for me when I had similar trouble..dunno why since if I logged in and then pasted the url to the secure page in the new window i got in (as expected since i was logged in) but when i used the full adress in my header it didnt work.
Re: session getting lost
Posted: Fri Mar 07, 2014 5:23 pm
by etsted
no, i am not using headers.
Re: session getting lost
Posted: Fri Mar 07, 2014 9:32 pm
by Christopher
Is the session data actually being written on the server? Perhaps it is a permissions or configuration problem.
Re: session getting lost
Posted: Sat Mar 08, 2014 3:37 am
by etsted
Code: Select all
<!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>
Re: session getting lost
Posted: Sat Mar 08, 2014 6:49 am
by Celauran
etsted wrote:Code: Select all
<!DOCTYPE html><?php session_start();?>
There's your problem. session_start sends out headers, which you've already sent. You should be seeing a "headers already sent" warning. Try placing the session_start call before sending any output to the browser.
Code: Select all
<?php session_start(); ?>
<!DOCTYPE html>
etc.
Re: session getting lost
Posted: Sat Mar 08, 2014 7:51 am
by jangmi
You can check /tmp folder in your server! This directory must be written