logo image

Gorilla3D Primative Teachings

Search

  Client Login



Get Firefox

Php Screencast Lession 07:
Keeping a User Logged in With Sessions


Code used in screencast

  1. <?php
  2.  
  3. if (isset($_POST['username']))
  4. {
  5.         $username = htmlentities($_POST['username']);
  6.         $password = htmlentities($_POST['password']);
  7.        
  8.         if ($username == 'bob' and $password == '123')
  9.         {
  10.                 $_SESSION['username'] = $username;
  11.                 echo 'Login Successful<br/>';
  12.                 echo  'Welcome, ' . $username;
  13.         }
  14.         else
  15.         {
  16.                 echo '<span style="color: red">Login Failed</span>';
  17.                 echo  $username . ', does not exsit';
  18.         }
  19. }
  20. ?>
  21.  
  22. <html>
  23. <head>
  24.         <title>My login</title>
  25. </head>
  26. <body>
  27.         <div></div>
  28.         <?php if (isset($_SESSION['username'])) { ?>
  29.         You are now logged in
  30.         <?php } else { ?>
  31.         <form action="" method="post">
  32.                 username: <input name="username" type="text" />
  33.                 password: <input name="password" type="password" />
  34.                 <input type="submit" />
  35.         </form>
  36.         <?php } ?>
  37. </body>
  38. </html>
  39.  

About Privacy Policy FAQ