daily pastebin goal
15%
SHARE
TWEET

PHP LogIn , LogOut and Session with Database Full tutorial

a guest Mar 20th, 2017 487 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Watch Videos here >> https://youtu.be/HKOnzjkFUDY
  2.  
  3. Here are the Codes.
  4.  
  5. Databas Connection
  6. ---dbcon.php
  7. <?php
  8. mysql_select_db('tutorial',mysql_connect('localhost','root',''));
  9. ?>
  10. Home Page
  11. ---home.php
  12. <?php
  13. include('dbcon.php');
  14. Session_start();
  15. if(!isset($_SESSION['id']))
  16. {
  17. header('location:index.html');
  18. }
  19.  
  20. ?>
  21. <html>
  22. <body>
  23. <?php
  24. $id=$_SESSION['id'];
  25. $result=mysql_query("Select * From account where id='$id'")or die(mysql_error);
  26. $row=mysql_fetch_array($result);
  27.  
  28. ?>
  29.  
  30. <h1>Hello!!, Welcome <?php echo $row['username'];?></h1> <br>
  31. <a href="logout.php">Logout</a>
  32.  
  33. </body>
  34. </html>
  35.  
  36. Login validation
  37. --login.php
  38. <?php
  39. include('dbcon.php');
  40. if(isset($_POST['submit']))
  41. $username=$_POST['username'];
  42. $password=$_POST['password'];
  43. $result=mysql_query("SELECT * FROM `tutorial`.`account` where username='$username' and password='$password' ") or die(mysql_error());
  44.  
  45. $count=mysql_num_rows($result);
  46. $row=mysql_fetch_array($result);
  47.  
  48. if($count > 0 )
  49. {
  50. session_start();
  51. $_SESSION['id']=$row['id'];
  52. header('location:home.php');
  53. }
  54. else
  55. {
  56. header('location:index.html');
  57. }
  58.  
  59. ?>
  60.  
  61. Log out
  62. ---logout.php
  63. <?php
  64. session_start();
  65. session_destroy();
  66. header('location:index.html');
  67. ?>
  68.  
  69. Main index
  70. ---index.html
  71. <html>
  72. <body>
  73.  
  74. <h1>Login form</h1>
  75. <form method="POST" action="login.php" style="width:40px">
  76. Username: <input type="text" name="username">
  77. Password: <input type="text" name="password">
  78.           <input type="submit" name="submit">
  79. </form>
  80.  
  81.  
  82.  
  83. </body>
  84. </html>
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93. Please Subscribe for more Videos tutorial.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top