User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 423,351 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 5,205 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 376 | Replies: 5 | Solved
Reply
Join Date: Apr 2008
Location: Lahore, Pakistan
Posts: 39
Reputation: mustafaneguib is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
mustafaneguib mustafaneguib is offline Offline
Light Poster

help please login problem this time

  #1  
Jun 21st, 2008
help please once again... my login page was working just fine when one morning it just stopped to function. now i have tried to fix it, buy changing some of the logic and also recreating the database.

now the point i have reached is that when the user enters his correct user name and correct password , the user is allowed access, but if the user gives a totally wrong username and password the access is denied. the problem now comes. when the user enters the correct user name but the wrong password he still is granted access. now i cant fix this problem.

by being granted access i mean the word hello is displayed, and by not allowed i mean the word no is displayed.

this happens when i replace
  1. include 'config.php';
  2. $connect=mysql_connect($hostname, $username, $password);
  3.  
  4. with
  5.  
  6. $connect=mysql_connect(hostnamevalue, usernamevalue, passwordvalue);
  7.  
  8.  
but if use the former one the user does not login at all. is the problem that i have used the session names and also the config.php variables of the same names, but i changed them and tried i couldnt login at all.
  1.  
  2.  
  3. <?php
  4.  
  5. session_start();
  6. $_SESSION['username']=$_POST['user'];
  7. $_SESSION['password']=$_POST['pass'];
  8. $_SESSION['authuser1']=0;
  9.  
  10.  
  11. include 'config.php';
  12. $connect=mysql_connect($hostname, $username, $password);
  13.  
  14. mysql_select_db("worldofp_blog1")
  15. or die(mysql_error());
  16.  
  17.  
  18.  
  19. $get="SELECT user_name, pass_word
  20. From user
  21. WHERE user_name = '" . $_SESSION['username'] . "'
  22. ORDER BY user_name";
  23.  
  24. $results=mysql_query($get)
  25. or die(mysql_error());
  26.  
  27.  
  28.  
  29. $get1="SELECT user_name, pass_word
  30. From user
  31. WHERE pass_word = '" . $_SESSION['password'] . "'
  32. ORDER BY user_name";
  33.  
  34. $result=mysql_query($get1)
  35. or die(mysql_error());
  36.  
  37.  
  38. $row=mysql_fetch_array($results, $result);
  39.  
  40.  
  41. $authuser= $row['user_name'];
  42. $authpass= $row['pass_word'];
  43.  
  44. if($authuser and $authpass)
  45. {
  46.  
  47. echo "hello";
  48. $_SESSION['authuser1']==1;
  49. }
  50. else
  51. {
  52. echo "no";
  53. $_SESSION['authuser1']==0;
  54. }
  55.  
  56.  
  57.  
  58. ?>
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
Last edited by mustafaneguib : Jun 21st, 2008 at 7:09 am.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: help please login problem this time

  #2  
Jun 21st, 2008
Few questions..
1. Why are you using sessions before authenticating the user ?
2. Why are you having 2 different queries for checking a valid user ?
3. order by user_name ? You don't need that actually !
And mysql_fetch_array's syntax is
mysql_fetch_array(result, result_type);
result_type = MYSQL_ASSOC or MYSQL_NUM.
$_SESSION['authuser1']==1;
== is a comparison operator, you should use = .
Isn't this a complete reduced version of your code ?
  1. <?php
  2. session_start();
  3.  
  4. include 'config.php'; //contains $hostname,$username,$password
  5.  
  6. $connect=mysql_connect($hostname, $username, $password); //connect
  7. mysql_select_db("worldofp_blog1") or die(mysql_error()); //select db
  8.  
  9. /* sanitize user's input */
  10. $user = mysql_real_escape_string($_POST['user']);
  11. $pass = mysql_real_escape_string($_POST['pass']);
  12.  
  13.  
  14. $get="SELECT user_name, pass_word from user where user_name='$user' and pass_word='$pass'"; //check if username and password exists
  15. $result=mysql_query($get) or die(mysql_error());
  16. $is_valid = mysql_num_rows ($result);
  17.  
  18. if($is_valid) { // if a record exist set $_SESSION['authuser1'] = 1
  19. echo "hello";
  20. $_SESSION['authuser1']=1;
  21. } else { //else set $_SESSION['authuser1'] = 0
  22. echo "no";
  23. $_SESSION['authuser1']=0;
  24. }
  25. ?>
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Apr 2008
Location: Lahore, Pakistan
Posts: 39
Reputation: mustafaneguib is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
mustafaneguib mustafaneguib is offline Offline
Light Poster

Re: help please login problem this time

  #3  
Jun 21st, 2008
thanks, alot. im actually more of a c++ programmer than a php programmer as ive done that in the uni. also this is my first php attempt so i dont know much about the rules of the php.

the two equals signs much have been left there by accident because i was copying and pasting the code from one area of my code to the other.
Last edited by mustafaneguib : Jun 21st, 2008 at 11:43 am.
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: help please login problem this time

  #4  
Jun 21st, 2008
ah! I see.. So, did it fix the problem or are you still facing some kinda problem ?
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Apr 2008
Location: Lahore, Pakistan
Posts: 39
Reputation: mustafaneguib is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
mustafaneguib mustafaneguib is offline Offline
Light Poster

Re: help please login problem this time

  #5  
Jun 21st, 2008
Originally Posted by nav33n View Post
ah! I see.. So, did it fix the problem or are you still facing some kinda problem ?


that fixed it thanx again
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: help please login problem this time

  #6  
Jun 21st, 2008
you are welcome!
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 11:56 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC