Advertisement
Guest User

login with redirect

a guest
Jan 7th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.72 KB | None | 0 0
  1. <?php
  2.  //Start a session
  3.   session_start();
  4.   //unset and reset any existing session
  5.   session_unset();
  6.   ?>
  7. <!DOCTYPE html>
  8. <html>
  9. <head>
  10. <script type="text/javascript">
  11. function delayedRedirect()
  12. {
  13. window.location = "url to page you want to go after login"
  14. }
  15. </script>
  16. </head>
  17. <body onLoad="setTimeout('delayedRedirect()', 8000)" style="background-color:#fff;">
  18.  
  19. <?php
  20. //this is a link to my connection string. you can type it here as well
  21. include 'tconslocal.php';
  22. //eg:  $con = mysqli_connect('server','username','password','database') or die('Unable To connect');
  23.  
  24. //assign variable here either through post or get
  25.  
  26. //for post use this
  27.  $username=mysqli_real_escape_string($con,$_POST['username']);
  28.  $password=mysqli_real_escape_string($con,$_POST['password']);
  29.  
  30. //for GET use this
  31.  $username=mysqli_real_escape_string($con,$_GET['username']);
  32.  $password=mysqli_real_escape_string($con,$_GET['password']);
  33.  
  34. $mysql_query="SELECT * FROM tablename where username= '$username' AND password= '$password'";
  35. $result = mysqli_query($con,$mysql_query);
  36. $count= mysqli_num_rows($result);
  37. // If result matched username and password, table row must be 1 row
  38. if($count>0)
  39. {
  40. //use this if you will be using the table information in the row returned
  41. while($row = $result->fetch_assoc())
  42. {
  43. //here iam assigning the id from the table row into a session variable so i can use it later
  44. $_SESSION['SESS_userID'] = $row['userid'];
  45. //close the session write process when done
  46. session_write_close();
  47. }
  48. echo "User Has Been Logged In Successfully. You will be redirected to the dashbooard in 5 seconds";
  49. exit;
  50. }
  51. else
  52. {
  53. echo "User Not Found. You will be redirected to the dashbooard in 5 seconds";
  54. exit;
  55. }
  56. ?>
  57. </body>
  58. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement