Advertisement
Guest User

Untitled

a guest
May 19th, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.20 KB | None | 0 0
  1. <?php
  2.  
  3. $username = sterilize( $_REQUEST['username'] );
  4. $password = sterilize( $_REQUEST['password'] );
  5. $sql = "SELECT * FROM users WHERE username = '$username' LIMIT 1";
  6.  
  7. $link = mysql_connect($host, $db_user, $db_password) or die('Could not connect: ' . mysql_error());
  8. mysql_select_db("$databaseName") or die("Could not select database");
  9. $result = mysql_query($query) or die("<p>Querying database failed: " . mysql_error());
  10. $record = mysql_fetch_array($result, MYSQL_ASSOC);
  11.  
  12. if(!$record)
  13. {
  14.     // Username not found in Dataase
  15.     header('Location: '.$error_page);
  16.     exit;
  17. }
  18.  
  19.  
  20. if( crypt( $password ) ) == $record['password'] )
  21. {
  22.     $_SESSION['username'] = $username;
  23.     header('Location: '.$success_page);
  24.     exit;
  25. }
  26.  
  27.  
  28. /////////////////////////////////////
  29. // Avoid SQL injection, and cross-site scripting
  30.  
  31. function sterilize($q, $is_sql=true)
  32. {
  33.  
  34.     if( !$is_sql ) $input = htmlentities($q, ENT_QUOTES);
  35.  
  36.     if( get_magic_quotes_gpc() )
  37.     {
  38.         // Remove possible existing magic quote quoting
  39.         $input = stripslashes($input);
  40.     }
  41.  
  42.     if($is_sql)
  43.     {
  44.         $input = mysql_real_escape_string($input);
  45.     }
  46.  
  47.     $input = strip_tags($input);
  48.     $input = str_replace("
  49.     ", "\n", $input);
  50.  
  51.     return $input;
  52. }
  53.  
  54. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement