Current location: Hot Scripts Forums » Programming Languages » PHP » True and Untrue at the same time (it doesn't make sense)

True and Untrue at the same time (it doesn't make sense)

Reply
  #1 (permalink)  
Old
Niall's Avatar
Newbie Coder
 
Join Date: Feb 2011
Location: Kernow
Posts: 93
Thanks: 11
Thanked 3 Times in 3 Posts
True and Untrue at the same time (it doesn't make sense)

I'm sure this is going to be another of my "ask for help and then realise I was being moronic" posts, but I have a very strange problem with one of my scripts:

PHP Code:

if($stored_pass == $password){
    
$_SESSION['user'] = $user['id'];
    
$_SESSION['HTTP_USER_AGENT'] = sha1(md5($_SERVER['HTTP_USER_AGENT']));
    
$log_details "Logged In";
    include(
"update_activity_log.php");
    
    
header('Location: '.$return_url.'');
    exit;
}
else{
    
$_SESSION['login'] = $_SESSION['login'] +1;
    
$log_details "Failed to log in (incorrect username or password)";
    include(
"update_activity_log.php");
    
header('Location: /pages/login.php?return='.$return_url.'&error=true7');
    exit;
}; 
Ok, the problem is when I use the correct login details, both the True and the False parts of the script are run. It logs me in and then sends me back to the login page with an error telling me I entered the wrong details.
I have verified that the script is correctly receiving the entered password (hashed) and the password stored on the database (also hashed) and they are exactly the same.
I've also tried this with seperate IF statements instead of an IF ELSE statement, but I get the same problem.
Reply With Quote

Featured Marketplace Scripts (view more)

  #2 (permalink)  
Old
Niall's Avatar
Newbie Coder
 
Join Date: Feb 2011
Location: Kernow
Posts: 93
Thanks: 11
Thanked 3 Times in 3 Posts
On further investigation I found a workaround, but I still don't know why the system isn't being logical.
I discovered that the login script wasn't receiving the return URL properly, so was returning the user to the login page after they had logged in.
Well, as predicted this is a "just realised I'm a moron" thread!
Reply With Quote
  #3 (permalink)  
Old
Newbie Coder
 
Join Date: Jul 2010
Posts: 32
Thanks: 0
Thanked 3 Times in 3 Posts
When it returns to the same page, first it checks that the login details are correct, and redirects to the same page, which then checks that the login details are incorrect (not filled in) and tells you that the information is wrong. But it still sets the session values correctly.

I hope this made some sense.
Reply With Quote
The Following User Says Thank You to Frement For This Useful Post:
Niall (11-22-12)
  #4 (permalink)  
Old
Niall's Avatar
Newbie Coder
 
Join Date: Feb 2011
Location: Kernow
Posts: 93
Thanks: 11
Thanked 3 Times in 3 Posts
Quote:
Originally Posted by Frement View Post
When it returns to the same page, first it checks that the login details are correct, and redirects to the same page, which then checks that the login details are incorrect (not filled in) and tells you that the information is wrong. But it still sets the session values correctly.

I hope this made some sense.
I had to read it a couple of times, but I think I get it. Thanks.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -5. The time now is 11:46 AM.
vBulletin® Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.