I'm brand new to .php. I understand it will validate data you enter (i.e. username and password)... I need a .php validation page like this that validates usernames & passwords to allow access into a wholesale only online store. Can someone tell me: 1. How to write the script? 2. Where I would store the usernames & passwords? Thanks! TxWebDesign
it is simple have a form <form method="post" action "page.php"> <input type="text" name="username"> <input type="password" name="pass"> <input type="submit" value="Log In"> then to validate that they are filled in <?php //get the posted data $username = $_POST["username"]; $pass = $_POST["pass"]; //then use IF to find out, having ! says not true if (!$username) { echo "You forgot to add your username"; }else{ if (!$password) { echo "You forgot to add your password"; }elese{ //Then run the MySQL query and log them in. PHP:
Hey, If you have MANY users store the username/passwords in a MySQL database. Table in the database: CREATE TABLE users ( userId INT(11) NOT NULL AUTO_INCREMENT, username CHAR(35) NOT NULL DEFAULT '', password CHAR(20) NOT NULL DEFAULT '', PRIMARY KEY userId(userId) ); Code (markup): Then you can do this similar to what only posted. <form method="post" action "page.php"> <input type="text" name="username"> <input type="password" name="pass"> <input type="submit" value="Log In"> Code (markup): page.php will be: <?php $username=$_POST[username]; $password=$_POSt[password]; //Be sure you do error checking and validating. $username=addslashes($username); $username=htmlspecialchars($username); $password=addslashes($password); $password=htmlspecialchars($password); if(!eregi("[a-zA-Z_0-9]",$username)){ echo "BAD USERNAME!"; exit; } if(!eregi("[a-zA-Z_0-9]",$password)){ echo "BAD PASSWORD!"; exit; } //If all is good $select=@mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password'"); if(mysql_num_rows($select)==0){ echo "Sorry your not a member."; }else{ echo "WELCOME BACK $username!!"; } Code (markup): You will need to connect to the db for the above to work. You should also do more field validating so it is safe for SQL injection. Hope this helps! P.S Sorry if there are script errors, just wrote it fast.
One thing to remeber, something I have noticed on a few pages. On the registration page, be sure to have password and re-type password. As i have said, I have seen a few sites with one password field to reg, you mis type your password, your screwed.
2 ways of doing that, the learner way Sends an email to you. The better way, They enter there name Then you run a MySQL query, grab the password, uncode the password, send an email with the username and password. Don't go for the secret question thing, because I don't know the answer to any of my secret questions no more. with email, then the person must have access to the email to gain access logged in.
Thanks for the responses. Based on your input, I thought I should better clarify what I need the script to do... So I would like to have an SQL database with usernames & passwords that I can add to and modify at any time (I'll contact my hosting company to figure out how to do this.) I would like the form to ask for the username and password, validate the input against the usernames & passwords in the database, and then if they match up, take them to a new URL (with the online restricted-access store.) Can someone point me to a sample code that I could tweak for my pages? Thank you!
Just look around at google for free php member scripts. You can find pretty much anything you want in search engines if you look hard enough. I typed 'free php scripts' in google and here is the first listing: http://www.free-php.net/scripts.php?id=8