Guest User

Untitled

a guest
Jun 7th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.22 KB | None | 0 0
  1. <?php
  2. //check for required fields
  3. if ((!$_POST["username"]) || (!$_POST["password"])) {
  4.     header("Location: index.php");
  5.     exit;
  6. }
  7.  
  8. //connect to mysql and select database
  9. $conn = mysql_connect('localhost', 'root', 'shutter0');
  10. if (!$conn) {
  11.     die('Could not connect: ' . mysql_error());
  12. }
  13. echo 'Connected successfully';
  14.  
  15. mysql_select_db("arcade",$conn) or die(mysql_error());
  16.  
  17. //create and issue the query
  18. $sql = "select f_name, l_name from arcade_users where username =  '$_POST[username]' AND password = password('$_POST[password]')";
  19. $result = mysql_query($sql, $conn) or die(mysql_error());
  20.  
  21. //get the number of rows in the result set; should be 1 if a match
  22. if (mysql_num_rows($result) == 1) {
  23.  
  24.     //if authorised, get the values of f_name l_name
  25.     $f_name = mysql_result($result, 0, 'f_name');
  26.     $l_name = mysql_result($result, 0, 'l_name');
  27.  
  28.     //set authorization cookie
  29.     setcookie("auth", "1", 0, "/", "localhost", 0);
  30.  
  31.     //create display string
  32.     $display_block = "<p>$f_name $l_name is authorized!</p>
  33.     <p>Authorized Users' Menu:
  34.     <ul>
  35.     <li><a href=\"secretpage.php\">secret page</a>
  36.     </ul>";
  37.  
  38. } else {
  39.  
  40.     //redirect back to login form if not authorized
  41.     header("Location: index.php");
  42.     exit;
  43. }
  44.  
  45.  
  46. ?>
Add Comment
Please, Sign In to add comment