Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // check that the user is calling the page from the login form and not accessing
- // it directly and redirect back to the login form in necessary.
- if(!isset($username) || !isset($password)){
- header("Location: localhost/login.htm");
- }
- // check that the form field are not empty, and redirect back to the login page
- // if they are
- elseif(empty($username)||empty($password)){
- header("Location: localhost/login.htm");
- }
- else{
- $user = addslashes($_POST['username']);
- $pass = md5($_POST['password']);
- //set the database connection variables
- $dbHost = "localhost";
- $dbUser = "webuser";
- $dbPass = "";
- $dbDatabase = "mydatabase";
- // connect to the database
- $db = mysql_connect("$dbHost", "$dbUser", "$dbPass") or die("Error connecting to database.");
- mysql_select_db("$dbDatabase", $db) or die("Coudln't select the databse.");
- $result=mysql_query("SELECT * FROM users WHERE userName='$user' AND userPass='$pass'", $db);
- $rowCheck = mysql_num_rows($result);
- if ($rowCheck > 0){
- while($row = mysql_fetch_array($result)){
- //Start the session and register a varaiable
- session_start();
- session_register('username');
- // Successful login code will go here...
- echo'Success!';
- // We will redirect the user to another page where we will make sure they're logged in.
- header("Location: checkLogin.php");
- }
- }
- else
- {
- // if nothing is returned by the query, unsuccessful login code goes here.
- echo 'Incorrect login name or password. Please Try again.';
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement