•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 401,961 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 2,841 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: 414 | Replies: 4
![]() |
•
•
Join Date: Oct 2007
Location: Penang Island, Malaysia
Posts: 170
Reputation:
Rep Power: 1
Solved Threads: 2
php Syntax (Toggle Plain Text)
<?php // auth.php // start session session_start(); // convert username and password from _POST or _SESSION if($_POST){ $_SESSION['username']=$_POST["username"]; $_SESSION['password']=$_POST["password"]; } // query for a user/pass match $result=mysql_query("select * from users where username='" . $_SESSION['username'] . "' and password='" . $_SESSION['password'] . "'"); // retrieve number of rows resulted $num=mysql_num_rows($result); // print login form and exit if failed. if($num < 1){ echo "You are not authenticated. Please login.<br><br> <form method=POST action=admin.php> username: <input type=text name=\"username\"> password: <input type=password name=\"password\"> <input type=submit> </form>"; exit; } ?>
This code prompt out username and password if there is no session found, but if u entered a wrong username, password or even leave in blank, it will just do nothing. How to do user input error checking, like empty username/password, imvalid password.
Please advise.
"I might not be the BEST but I'm not like the REST!"
php Syntax (Toggle Plain Text)
if(empty($_POST['username'])){ echo"Please enter username"; } if(empty($_POST['password'])){ echo"Please enter password"; }
php Syntax (Toggle Plain Text)
mysql_real_escape_string(htmlspecialchars($_SESSION['username'])); mysql_real_escape_string(htmlspecialchars($_SESSION['password']));
Last edited by buddylee17 : Mar 7th, 2008 at 9:44 am.
•
•
Join Date: Oct 2007
Location: Penang Island, Malaysia
Posts: 170
Reputation:
Rep Power: 1
Solved Threads: 2
Thanks buddylee17, the thing is, I'm calling this auth.php in every page, I've already tried the method you mentioned above, after you logged in successfully, The echo statements will be on every page that includes auth.php. Any other suggestions?
"I might not be the BEST but I'm not like the REST!"
Not sure I understand your situation. How about a redirect to the login if the session isn't valid?
php Syntax (Toggle Plain Text)
if(empty($_SESSION['username']) || empty($_SESSION['password'])){ header ('Location:login.php?please_login'); }
•
•
Join Date: Oct 2007
Location: Penang Island, Malaysia
Posts: 170
Reputation:
Rep Power: 1
Solved Threads: 2
Situation:
The auth.ph was placed on every single page of my except the index.html and logout.php. I want to access direct to an admin type page (e.g. localhost/cycle/addlist.php) it would prompt a login message. If I place the
even after I logged in with correct username and password, the echo will be displayed on addlist.php.
The auth.ph was placed on every single page of my except the index.html and logout.php. I want to access direct to an admin type page (e.g. localhost/cycle/addlist.php) it would prompt a login message. If I place the
php Syntax (Toggle Plain Text)
if(empty($_POST['username'])){ echo"Please enter username"; }
"I might not be the BEST but I'm not like the REST!"
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- PHP tags into HTML tags (PHP)
- Array values for validation (PHP)
- Custom error checking (C#)
- User Form error checking (PHP)
Other Threads in the PHP Forum
- Previous Thread: PHP MSSQL Stored Procedure with Parameters (In and Out)
- Next Thread: Getting information from database and display on the screen


Linear Mode