•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 391,994 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 4,283 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: 337 | Replies: 5 | Solved
![]() |
•
•
Join Date: Apr 2008
Location: Lahore, Pakistan
Posts: 36
Reputation:
Rep Power: 1
Solved Threads: 1
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
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.
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
php Syntax (Toggle Plain Text)
include 'config.php'; $connect=mysql_connect($hostname, $username, $password); with $connect=mysql_connect(hostnamevalue, usernamevalue, passwordvalue);
php Syntax (Toggle Plain Text)
<?php session_start(); $_SESSION['username']=$_POST['user']; $_SESSION['password']=$_POST['pass']; $_SESSION['authuser1']=0; include 'config.php'; $connect=mysql_connect($hostname, $username, $password); mysql_select_db("worldofp_blog1") or die(mysql_error()); $get="SELECT user_name, pass_word From user WHERE user_name = '" . $_SESSION['username'] . "' ORDER BY user_name"; $results=mysql_query($get) or die(mysql_error()); $get1="SELECT user_name, pass_word From user WHERE pass_word = '" . $_SESSION['password'] . "' ORDER BY user_name"; $result=mysql_query($get1) or die(mysql_error()); $row=mysql_fetch_array($results, $result); $authuser= $row['user_name']; $authpass= $row['pass_word']; if($authuser and $authpass) { echo "hello"; $_SESSION['authuser1']==1; } else { echo "no"; $_SESSION['authuser1']==0; } ?>
Last edited by mustafaneguib : Jun 21st, 2008 at 7:09 am.
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 238
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.
== is a comparison operator, you should use = .
Isn't this a complete reduced version of your code ?
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;
Isn't this a complete reduced version of your code ?
php Syntax (Toggle Plain Text)
<?php session_start(); include 'config.php'; //contains $hostname,$username,$password $connect=mysql_connect($hostname, $username, $password); //connect mysql_select_db("worldofp_blog1") or die(mysql_error()); //select db /* sanitize user's input */ $user = mysql_real_escape_string($_POST['user']); $pass = mysql_real_escape_string($_POST['pass']); $get="SELECT user_name, pass_word from user where user_name='$user' and pass_word='$pass'"; //check if username and password exists $result=mysql_query($get) or die(mysql_error()); $is_valid = mysql_num_rows ($result); if($is_valid) { // if a record exist set $_SESSION['authuser1'] = 1 echo "hello"; $_SESSION['authuser1']=1; } else { //else set $_SESSION['authuser1'] = 0 echo "no"; $_SESSION['authuser1']=0; } ?>
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*
*PM asking for help will be ignored*
•
•
Join Date: Apr 2008
Location: Lahore, Pakistan
Posts: 36
Reputation:
Rep Power: 1
Solved Threads: 1
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.
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.
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 238
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*
*PM asking for help will be ignored*
•
•
Join Date: Apr 2008
Location: Lahore, Pakistan
Posts: 36
Reputation:
Rep Power: 1
Solved Threads: 1
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
- Login problem (C#)
- Login problem (C#)
- Windows XP slow login (Windows NT / 2000 / XP / 2003)
- Login Problem. Please Help. (PHP)
- Can't login to DaniWeb (DaniWeb Community Feedback)
- lsass.exe login problem (Windows NT / 2000 / XP / 2003)
- Netscape 7.1, Hotmail login problem - cookies 'disabled" (Windows NT / 2000 / XP / 2003)
- Internet Explorer Display problem! (Web Browsers)
Other Threads in the PHP Forum
- Previous Thread: Divide time
- Next Thread: Data between dates again



you are welcome!
Linear Mode