Guest User

Untitled

a guest
Dec 14th, 2011
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. <?php
  2. session_start();
  3.  
  4. //This displays your login form
  5. function index(){
  6.  
  7. echo "<form action='?act=login' method='post'>"
  8. ."Username: <input type='text' name='username' size='30'><br>"
  9. ."Password: <input type='password' name='password' size='30'><br>"
  10. ."<input type='submit' value='Login'>"
  11. ."</form>";
  12.  
  13. }
  14.  
  15. //This function will find and checks if your data is correct
  16. function login(){
  17.  
  18. //Collect your info from login form
  19. $username = $_REQUEST['username'];
  20. $password = $_REQUEST['password'];
  21.  
  22.  
  23. //Connecting to database
  24. $connect = mysql_connect("localhost:3306","root","1234");
  25. if(!$connect){
  26. die(mysql_error());
  27. }
  28.  
  29. //Selecting database
  30. $select_db = mysql_select_db("youtube", $connect);
  31. if(!$select_db){
  32. die(mysql_error());
  33. }
  34.  
  35. //Find if entered data is correct
  36. $result = mysql_query("SELECT * FROM user WHERE username='$username' AND password='$password'");
  37. $row = mysql_fetch_array($result);
  38. $id = $row['id'];
  39.  
  40. $select_user = mysql_query("SELECT * FROM user WHERE id='$id'");
  41. $row4 = mysql_fetch_array($select_user);
  42. $user = $row4['username'];
  43.  
  44. if($username != $user){
  45. die("Username is wrong!");
  46. }
  47.  
  48. $pass_check = mysql_query("SELECT * FROM user WHERE username='$username' AND id='$id'");
  49. $row3 = mysql_fetch_array($pass_check);
  50. $email = $row3['email'];
  51. $select_pass = mysql_query("SELECT * FROM user WHERE username='$username' AND id='$id' AND email='$full'");
  52. $row5 = mysql_fetch_array($select_pass);
  53. $real_password = $row5['password'];
  54.  
  55. if($password != $real_password){
  56. die("Your password is wrong!");
  57. }
  58.  
  59. //Now if everything is correct let's finish his/her/its login
  60.  
  61. session_register("username", $username);
  62. session_register("password", $password);
  63.  
  64. echo "Welcome, ".$username." please continue on our <a href=index.php>Index</a>";
  65.  
  66. }
  67.  
  68. switch($act){
  69.  
  70. default;
  71. index();
  72. break;
  73.  
  74. case "login";
  75. login();
  76. break;
  77.  
  78. }
  79. ?>
Advertisement
Add Comment
Please, Sign In to add comment