Page 1 of 1

Weird Logon Problem

Posted: Wed Jul 30, 2008 8:20 am
by dajawu
Ok so heres the problem. I had a logon script that worked fine but wasn't as nice as I wanted. So I changed it around a little so after your logged on it will send you to the home page. Also it sets a few session variables and when they are set a User Menu pops up on the left of the screen. For some reason certain users have to log in twice to get it to work. It doesn't happen to me so I don't know whats wrong, but it does happen to several of my users. There is no common browser or even OS so I have no clue. The code is below:

Code: Select all

 
$lastlogin = date('Y-m-d H:i:s');
    $sql = "UPDATE Users SET lastlogin='$lastlogin' WHERE UserID=$row[0]";
    mysql_query($sql) or die("Can't insert last login info");
    //echo "<span class=alert>You have been logged on! You may proceed!</span>";
   
    $_SESSION['UN'] = (string)$row[1];
    $_SESSION['UI'] = (int)$row[0];
    $_SESSION['isAdmin'] = (int)$row[11];
    header("Location: http://snuffreviews.com/index.php");
 
Now this code is only executed if the password matches the password in the datebase. So for this code to be executed the username and password have already been verified. So for the person that has to log on twice this is what happens:

He/She logs on with correct Name and Password
The above code gets executed and they are Redirect to index.php
The problem is they are not logged in and the User menu does not show up so
He/She logs in again with the same info
The second time around they are always allowed in ?

Any idea why it takes two times for the above code to work for some people? For others like myself it works on the first try. Feel free to test out the real thing at SnuffReviews.com, just let me know to get rid of your account after.

Re: Weird Logon Problem

Posted: Wed Jul 30, 2008 8:33 am
by ody3307
Have you made sure each page checks for the session? That causes regular problems for me as I tend to forget.

Is the code you have here working properly? You have a variable inside single quotes in the query. It shouldn't work properly. I'm curious if your lastlogin is actually updating.

Re: Weird Logon Problem

Posted: Wed Jul 30, 2008 8:38 am
by dajawu
Yes everything works fine. Most of my users logon fine the first time, and their last login is updated, then they are redirected to the home page which shows their user menu on the left. This works fine for most people, but every now and again I get someone who needs to do this twice. It ALWAYS works on the second time for those users.

Re: Weird Logon Problem

Posted: Wed Jul 30, 2008 4:32 pm
by andychamberlainuk
Try putting session_start(); at the beginning of login and index page. It may be that the session variables are not transfering. You could also try echoing your session variable in the new page to see if they are being set properly.

btw, do you have the rest of your code?

Re: Weird Logon Problem

Posted: Sat Aug 02, 2008 11:59 pm
by dajawu
I couldn't get on this site for a few days for some reason. So now I can update this post.

I have session_start in both pages, and as I said before this page works just fine for me. Its some of my users who have problems with it. I actually had it happen to me a few times but not anymore. Also it always works on the second time so the varialbes work just fine the second time around. I know the above code is getting executed because even though the user doesn't get logged on he still gets transfered to index.php so I know all those lines are getting ran. Why would this happen? It just doesn't make sence!

Re: Weird Logon Problem

Posted: Sun Aug 03, 2008 12:32 am
by dajawu
Another strange thing about this all is this. In order to use the Header function I have this code at the top of my page so it won't have issues. If I take out the header function and put this code back down in my script where I had it, it works fine. The users that had trouble don't anymore? I have no clue why this is.