Advertisement
Guest User

login

a guest
Mar 6th, 2015
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.24 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <?php
  3. include("config.php"); // including our config.php where is connecting to mysql...
  4. session_start();
  5. error_reporting(0); //without this we will always get some stupid notice that variable isn't defined....
  6.  
  7. // establishing the MySQLi connection
  8.  
  9. /*$con = mysqli_connect("localhost","root","","sa-mp");
  10.  
  11. if (mysqli_connect_errno())
  12. {
  13.     echo "MySQLi Connection was not established: " . mysqli_connect_error();
  14. }*/
  15.  
  16. // checking the user
  17. $submit = $_POST['submit']; //variable for submit button, in this variable we save button that player press in <input type='submit' name="submit" value='Login' />....
  18.  
  19. $username = mysqli_real_escape_string($con,$_POST['Username']);
  20. $pass = mysqli_real_escape_string($con, $_POST['Password']);
  21. $passw = strtoupper(hash( 'whirlpool',$pass));
  22.  
  23.     if($submit) //if he press submit button
  24.     {
  25.         if($username && $passw) //if he type both of username and password not just one of them
  26.         {
  27.             $query = mysqli_query("SELECT * FROM `players` WHERE 'Username' = '$username' AND Password='$passw'"); //selecting user name and password, change it to your field names,  chage users to your table name, $username means username that he type...
  28.             if(mysqli_num_rows($query) == 1) //if user exists
  29.             {
  30.                 while($row = mysqli_fetch_assoc($query)) //loop thought table that we select in mysql_query
  31.                 {
  32.                     $dbusername = $row['Username']; //setting dbusername as variable from table, change 'username' to your field!
  33.                     $dbpassword = $row['Password']; //setting dbpassword as variable from table, change 'password' to your field!
  34.                 }
  35.                 if($username == $dbusername && $passw == $dbpassword) //if username is same as one from table and if password is the same as one from table...
  36.                 {
  37.                     $_SESSION['Username'] = $dbusername; //setting session username to one from table, this is useful if you login, that restart your browser and than you go in url where is your profile.php... Anyway this is useful :D
  38.                     echo header('location: profile.php'); //redirecting user to his profile page (profile.php)
  39.                    //echo "<script>window.open('home.php','_self')</script>";
  40.                 }
  41.                 else
  42.                 {
  43.                     echo "<script>alert('Username or password is not correct, try again!')</script>";
  44.                 }
  45.             }
  46.         }
  47.     }
  48.  
  49.  
  50. function Whirlpool($str)
  51. {
  52.     return strtoupper(hash('whirlpool', $str));
  53. }
  54. ?>
  55.  
  56. <html>
  57.     <head>
  58.         <title>User Login</title>
  59.     </head>
  60.         <body>
  61.             <form action="login.php" method="post">
  62.            
  63.                 <table width="500" align="center" bgcolor="skyblue">
  64.                
  65.                     <tr align="center">
  66.                    
  67.                         <td colspan="3"><h2>User Login</h2></td>
  68.                        
  69.                         </tr>
  70.                        
  71.                     <tr>
  72.  
  73.                         <td align="right"><b>Username</b></td>
  74.                
  75.                             <td><input type="text" name="Username" required="required "/></td>
  76.            
  77.                             </tr>
  78.                         <tr>
  79.                             <td align="right"><b>Password:</b></td>
  80.                        
  81.                                 <td><input type="password" name="Password" required="required"></td>
  82.  
  83.                                 </tr>  
  84.                             <tr align="center">
  85.                
  86.                                 <td colspan="3">
  87.                            
  88.                                     <input type="submit" name="login" value="Login"/>
  89.                                 </td>
  90.                             </tr>
  91.                     </table>
  92.             </form>
  93.         </body>
  94. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement