Page 1 of 1

On refreshing the page the application gets loged out

Posted: Mon May 04, 2009 1:21 am
by sulekha
Hi all,

I made a php application ,it is working well in mozilla but in I.E , sometimes the application gets logged out on refreshing the page ?

Re: On refreshing the page the application gets loged out

Posted: Mon May 04, 2009 1:47 am
by Benjamin
:arrow: Moved to PHP - Code

Re: On refreshing the page the application gets loged out

Posted: Mon May 04, 2009 2:56 am
by mickd
What method are you using to store whether a user is logged in? Posting a bit of your code that handles that, and how you check if a user is logged in might help too.

It may also be a browser setting too.

Re: On refreshing the page the application gets loged out

Posted: Mon May 04, 2009 5:06 am
by sulekha
mickd wrote:What method are you using to store whether a user is logged in? Posting a bit of your code that handles that, and how you check if a user is logged in might help too.

It may also be a browser setting too.

here is the code

Code: Select all

 
if( isset($_POST['submit']) )
{  
 $usn=trim($_POST['username']);
 $pass=trim($_POST['password']);
 
 $sql= "SELECT * FROM user where username='$usn' AND password='$pass'";
 $result = mysql_query($sql,$con);
 $var = mysql_fetch_array($result);
 $_SESSION['usertype']=$var[3];
 
$feildName="Username Field is required";
$feildName1="Password Field is required";
$feildName2="Enter Correct Username";
$feildName3="Enter Correct password";
 
 
  if($err<>1)
 {
 if($var[3]==1)
 {
  $_SESSION['username']=$var[1];
   header("location:Admin_index.php");
 }
 else if($var[3]==3)
 {
  $_SESSION['username']=$var[1];
  header("location:Admin_index.php");
 }
 else
 {
  header("location:login.php");
 }
}
}
//mysql_close();
?>
 
what is the browser setting that i should set ?

Re: On refreshing the page the application gets loged out

Posted: Mon May 04, 2009 3:33 pm
by infolock
something tells me that submit isn't the issue as $_POST['submit'] will be set if you actually posted the page.

And if $_POST['submit'] weren't set, you wouldn't be getting redirected.

The issue lies in this piece of code:

Code: Select all

 
 if($err <> 1) {
   if($var[3] == 1) {
      $_SESSION['username']=$var[1];
      header("location:Admin_index.php");
   } else if($var[3] == 3) {
     $_SESSION['username']=$var[1];
     header("location:Admin_index.php");
   } else {
     header("location:login.php");
   }
 
I would recommend doing an echo and exit on each of those if statements above to determine which one is ringing true, and then debugging from there.

Re: On refreshing the page the application gets loged out

Posted: Fri May 08, 2009 3:51 pm
by infolock
I understand what you mean, but his piece of code shows a redirection based on $_POST['submit'] being set. And since $_POST['submit'] can only be set when the page is posted, and also since the redirects are only within the conditional if(isset($_POST['submit'])), it still means that the button is indeed set and working ok. Either way, I'm sure once he debugs this a little more he'll see the answer.