Jump to content

sessions


etsted

Recommended Posts

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

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 by etsted
Link to comment
Share on other sites

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

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 by etsted
Link to comment
Share on other sites

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...