Jump to content
Sign in to follow this  
etsted

sessions

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.

Share this post


Link to post
Share on other sites

I've never heard of a problem like that. What exactly are you seeing happen? What does "don't work" mean?

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...