I am trying to set up a login system for my website that requires someone to log in to post. I installed it with sessions and it works fine on my localhost, but not on the server. I set print_r (session) on some pages to see where the data loss is. On the checklogin.php page, which is the page that starts when you log in, it works fine. Here is the code from there:
<?php
session_name('login_session');
session_start();
mysql_connect("localhost","root","root") or die(mysql_error());
mysql_select_db("date_ideas") or die(mysql_error());
$uname=$_POST['uname'];
$uname=mysql_real_escape_string($uname);
$pass=$_POST['pass'];
$pass=mysql_real_escape_string($pass);
$pass=md5($pass);
$query="SELECT * FROM users WHERE uname='$uname' AND pass='$pass'";
$result=mysql_query($query) or die(mysql_error());
$numrows=mysql_num_rows($result);
echo $numrows;
if ($numrows==1)
{
$_SESSION['login']="1";
$_SESSION['uname']=$uname;
echo "<script type='text/javascript'>alert('match');</script>";
print_r($_SESSION);
}
else
{
$_SESSION['login']="";
echo "<script type='text/javascript'>alert('Invalid Login');</script>";
echo "<script type='text/javascript'>window.location = 'login.php?uname=$uname'</script>";
}
?>
When I submit a form with good registration information, a warning appears and the print returns:
Array ([login] => 1 [uname] => FrizbeeFanatic14)
So, at this moment it works. However, when I go to the main page, the print becomes:
Array ()
, . :
<?php
session_name('login_session');
session_start();
?>
<html>
<head>
<title>Great Date Ideas</title>
<link rel="stylesheet" type="text/css" href="mainstyle.css" />
<script type="text/javascript" src="validate.js"></script>
<script type="text/javascript" src="cookiecheck.js"></script>
</head>
<body onload="checkCookie()">
<script type="text/javascript">
if (detect=false)
{
document.write("You must enable cookies to view this page.");
window.stop();
document.execCommand('Stop');
}
</script>
<div id="home"><?php require("header.php");?></div>
<?php
print_r($_SESSION);
mysql_connect("localhost","root","root") or die(mysql_error());
mysql_select_db("date_ideas") or die(mysql_error());
$result=mysql_query("SELECT * FROM ideas ORDER BY post_date DESC") or die(mysql_error());
, , , .
, localhost, .