On refreshing the page the application gets loged out

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sulekha
Forum Newbie
Posts: 2
Joined: Mon May 04, 2009 1:18 am

On refreshing the page the application gets loged out

Post 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 ?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: On refreshing the page the application gets loged out

Post by Benjamin »

:arrow: Moved to PHP - Code
mickd
Forum Contributor
Posts: 397
Joined: Tue Jun 21, 2005 9:05 am
Location: Australia

Re: On refreshing the page the application gets loged out

Post 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.
sulekha
Forum Newbie
Posts: 2
Joined: Mon May 04, 2009 1:18 am

Re: On refreshing the page the application gets loged out

Post 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 ?
Last edited by Benjamin on Mon May 04, 2009 8:50 am, edited 1 time in total.
Reason: Added [code=php] tags.
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Re: On refreshing the page the application gets loged out

Post 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.
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Re: On refreshing the page the application gets loged out

Post 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.
Post Reply