Advertisement
Guest User

Untitled

a guest
Jun 6th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. <?php
  2. // check that the user is calling the page from the login form and not accessing
  3. // it directly and redirect back to the login form in necessary.
  4. if(!isset($username) || !isset($password)){
  5. header("Location: localhost/login.htm");
  6. }
  7. // check that the form field are not empty, and redirect back to the login page
  8. // if they are
  9. elseif(empty($username)||empty($password)){
  10. header("Location: localhost/login.htm");
  11. }
  12. else{
  13. $user = addslashes($_POST['username']);
  14. $pass = md5($_POST['password']);
  15.  
  16. //set the database connection variables
  17.  
  18. $dbHost = "localhost";
  19. $dbUser = "webuser";
  20. $dbPass = "";
  21. $dbDatabase = "mydatabase";
  22.  
  23. // connect to the database
  24.  
  25. $db = mysql_connect("$dbHost", "$dbUser", "$dbPass") or die("Error connecting to database.");
  26.  
  27. mysql_select_db("$dbDatabase", $db) or die("Coudln't select the databse.");
  28.  
  29. $result=mysql_query("SELECT * FROM users WHERE userName='$user' AND userPass='$pass'", $db);
  30.  
  31. $rowCheck = mysql_num_rows($result);
  32. if ($rowCheck > 0){
  33. while($row = mysql_fetch_array($result)){
  34. //Start the session and register a varaiable
  35. session_start();
  36. session_register('username');
  37.  
  38. // Successful login code will go here...
  39. echo'Success!';
  40. // We will redirect the user to another page where we will make sure they're logged in.
  41. header("Location: checkLogin.php");
  42. }
  43. }
  44. else
  45. {
  46. // if nothing is returned by the query, unsuccessful login code goes here.
  47.  
  48. echo 'Incorrect login name or password. Please Try again.';
  49.  
  50. }
  51. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement