session getting lost
Moderator: General Moderators
session getting lost
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
Can you elaborate on that?etsted wrote:but wheni upload them to a server they dont work
Re: session getting lost
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
Have you inspected the $_SESSION array? Are any errors being displayed (or logged)? Is error reporting on?
Re: session getting lost
what u mean? it works localy when i run the script on my pc no errors.
Re: session getting lost
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
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
If you like read this: http://strangerzlog.blogspot.it/2012/04 ... ns-on.html
Re: session getting lost
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.
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
no, i am not using headers.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: session getting lost
Is the session data actually being written on the server? Perhaps it is a permissions or configuration problem.
(#10850)
Re: session getting lost
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
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.etsted wrote:Code: Select all
<!DOCTYPE html><?php session_start();?>
Code: Select all
<?php session_start(); ?>
<!DOCTYPE html>
etc.Re: session getting lost
You can check /tmp folder in your server! This directory must be written