wincode
11-12-2011, 10:00 PM
Hi I'm having problems with a login code. The problem is that the first time I login, then go to a different page, it logs me out. But on the second login, this problem doesn't happen.
I use a page login.php to process login:
<?php
mysql connection stuff
session_start();
$user=$_POST['user'];
$pass=$_POST['pass'];
$loginchek=mysql_query("SELECT * FROM users where user='$user'") or die(mysql_error());
$loginchek2=mysql_fetch_array($loginchek);
if($loginchek2['pass']==$pass){
$_SESSION['user']=$loginchek2['user'];
$_SESSION['userid']=$loginchek2['id'];
header('Location: index.php');
echo"You are now logged in!";
}
else{
echo"Wrong password";
}
?>
What could be causing the problem?
Thanks
I use a page login.php to process login:
<?php
mysql connection stuff
session_start();
$user=$_POST['user'];
$pass=$_POST['pass'];
$loginchek=mysql_query("SELECT * FROM users where user='$user'") or die(mysql_error());
$loginchek2=mysql_fetch_array($loginchek);
if($loginchek2['pass']==$pass){
$_SESSION['user']=$loginchek2['user'];
$_SESSION['userid']=$loginchek2['id'];
header('Location: index.php');
echo"You are now logged in!";
}
else{
echo"Wrong password";
}
?>
What could be causing the problem?
Thanks