Help login issue

Reply

Join Date: Jul 2008
Posts: 4
Reputation: headfirst is an unknown quantity at this point 
Solved Threads: 0
headfirst's Avatar
headfirst headfirst is offline Offline
Newbie Poster

Help login issue

 
0
  #1
Jul 19th, 2008
Hi php gurus. newbie here needs help.

I m having a problem with my login script. Basically it works 95% of the time, but once and a while it doesn't. The session variable doesn't get set, or remembered, and the next referred page fails on the isset check. I tried a number of things, Please any suggestions would be great. My code is pretty messy...at the moment... but I've been going nuts with this. I recently added the session_regenerate_id and the session_write function to no avail.

snipplet from login.php.

  1. //Start session
  2. session_start();
  3. sql="SELECT login,id FROM tblDealer WHERE login='".$email."' and password='".$password."'";
  4. $r = mysql_query($sql);
  5. $row=mysql_fetch_array($r);
  6.  
  7. if($r) {
  8. if(mysql_num_rows($r)>0) {
  9. //Login Successful
  10. session_regenerate_id();
  11. //$member=mysql_fetch_assoc($r);
  12. //$_SESSION['dealer_id']=$member['id'];
  13. $_SESSION['dealer_id']=$row["id"];
  14. session_write_close();
  15. //header("location: client.php");
  16. $dealer_id = $row["id"];
  17. print 'success,client.php,dealer='.$dealer_id; // maybe add it to the url ? just for now.
  18. exit();
  19. }else {
  20. //Login failed
  21. //header("location: login-failed.php");
  22. print "no such login in the system. please try again.";
  23. exit();
  24. }
  25. }else {
  26. die("Query failed");
  27. }
Next Page. Client.php
I use this check to confirm the session is there.

  1. session_start();
  2.  
  3.  
  4. if(!isset($_SESSION['dealer_id'])) {
  5. echo '<p>Security Violation ';
  6. exit();
  7. }
Last edited by Tekmaven; Jul 19th, 2008 at 2:36 pm. Reason: Code tags
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 89
Reputation: camilojvarona is an unknown quantity at this point 
Solved Threads: 10
camilojvarona camilojvarona is offline Offline
Junior Poster in Training

Re: Help login issue

 
0
  #2
Jul 19th, 2008
Hi,

I am as newbie to PHP as you but in this line you missed teh '$' symbol.

  1. sql="SELECT login,id FROM tblDealer WHERE login='".$email."' and password='".$password."'";

in front of the sql variable

$sql

Although you can go to this link

http://us2.php.net/manual/en/function.mysql-query.php

Hope this help,
Camilo
Last edited by camilojvarona; Jul 19th, 2008 at 12:58 pm.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 4
Reputation: headfirst is an unknown quantity at this point 
Solved Threads: 0
headfirst's Avatar
headfirst headfirst is offline Offline
Newbie Poster

Re: Help login issue

 
0
  #3
Jul 19th, 2008
Thanks Camilo, I missed that character when pasting into this thread but it is there in my code...
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 89
Reputation: camilojvarona is an unknown quantity at this point 
Solved Threads: 10
camilojvarona camilojvarona is offline Offline
Junior Poster in Training

Re: Help login issue

 
0
  #4
Jul 19th, 2008
Hi,

What program are you using for debugin your application?. I am using PHP Designer. I think that it would be useful to see what warnings does it give you.

Camilo
Last edited by camilojvarona; Jul 19th, 2008 at 1:05 pm.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 4
Reputation: headfirst is an unknown quantity at this point 
Solved Threads: 0
headfirst's Avatar
headfirst headfirst is offline Offline
Newbie Poster

Re: Help login issue

 
0
  #5
Jul 19th, 2008
nothing really.... I guess I should really start using something.
But like I said it works 95% of the time, I can't reproduce the problem consistently, it seems to happen randomly.....thx
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 4
Reputation: headfirst is an unknown quantity at this point 
Solved Threads: 0
headfirst's Avatar
headfirst headfirst is offline Offline
Newbie Poster

Re: Help login issue

 
0
  #6
Jul 20th, 2008
..anyone have any ideas...???
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 850
Reputation: R0bb0b is on a distinguished road 
Solved Threads: 67
R0bb0b's Avatar
R0bb0b R0bb0b is offline Offline
Practically a Posting Shark

Re: Help login issue

 
0
  #7
Jul 20th, 2008
Try eliminating one problem at a time. create a page with just this code in it and refresh it several times, if it resets to zero then you have a problem, if not, I'm pretty sure that it is not a problem with the session.
  1. <?
  2. session_start();
  3. if(!isset($_SESSION['sesstest']) || !is_numeric($_SESSION['sesstest']))
  4. {
  5. $_SESSION['sesstest'] = 0;
  6. }
  7. else
  8. {
  9. $_SESSION['sesstest']++;
  10. }
  11. echo $_SESSION['sesstest'];
  12. ?>
Last edited by R0bb0b; Jul 20th, 2008 at 3:30 am.
“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” - Dr. Seuss

-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2
Reputation: php-lover is an unknown quantity at this point 
Solved Threads: 0
php-lover php-lover is offline Offline
Newbie Poster

try this code

 
0
  #8
Jul 20th, 2008
  1. //Start session
  2. session_start();
  3. $sql="SELECT login,id FROM tblDealer WHERE login='".$email."' and password='".$password."'";
  4.  
  5. if($result = mysql_query($sql)) {
  6.  
  7. if(mysql_num_rows($result)>0) {
  8.  
  9. list($login,$id) = mysql_fetch_array($result);
  10.  
  11. $_SESSION['dealer_id']= $id;
  12.  
  13. print 'success,client.php,dealer='.$id; // maybe add it to the url ? just for now.
  14. exit();
  15.  
  16. }else {
  17.  
  18. print "no such login in the system. please try again.";
  19. exit();
  20. }//else
  21.  
  22. } else{
  23.  
  24. die("Query failed");
  25. }
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 850
Reputation: R0bb0b is on a distinguished road 
Solved Threads: 67
R0bb0b's Avatar
R0bb0b R0bb0b is offline Offline
Practically a Posting Shark

Re: try this code

 
0
  #9
Jul 20th, 2008
actually, I really don't see much difference, but it looks much cleaner.
Last edited by R0bb0b; Jul 20th, 2008 at 5:25 am.
“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” - Dr. Seuss

-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC