Advertisement
gitlez

YA: Simple Login Check

Apr 12th, 2012
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.92 KB | None | 0 0
  1. <?php
  2. // In response to a Yahoo Answer's question
  3. session_start();
  4.  
  5. $username = $_POST['username'];
  6. $password = $_POST['password'];
  7.  
  8. if ($username && $password){
  9.     $connect = mysql_connect("localhost", "par24_user", "*password*") or die("Couldn't Connect!");
  10.     mysql_select_db("par24_user")or die ("Couldn't find db!");
  11.    
  12.     $username = mysql_real_escape_string($username);
  13.     $password = md5($password);
  14.    
  15.     $result = mysql_query( "SELECT username FROM user WHERE username='" . $username . "' AND password='" . $password . "' LIMIT 1");
  16.    
  17.     if($result && mysql_num_rows($result) > 0){
  18.         $_SESSION['username'] = mysql_fetch_object($result)->username;
  19.         echo "You've Logged on! <a href='member.php'</a> Click here to eneter member page.";
  20.     }else{
  21.         echo 'Invalid Username/Password Combination. <a href="' . $_SERVER['HTTP_REFERER'] . '">Click To Return</a>';
  22.     }
  23. } else {
  24.     die ("Please enter a username and password!");
  25. }
  26.  
  27. ?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement