Advertisement
MadeCurler

Session varaibles

Jan 12th, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.37 KB | None | 0 0
  1. / *  here are the session.php variables...
  2.  
  3.     private $signed_in = false;
  4.     public  $user_id;
  5.     public $count;
  6.     public $message;
  7.     public $first_name;
  8.     public $username;
  9.     public $password;
  10. */
  11.  
  12. //************the login function in session.php*********//
  13.  
  14. public function login($user) {
  15.  
  16. // we have a user
  17.     if($user) {
  18.        
  19.         $this->first_name = $_SESSION['first_name'] = $user->first_name;
  20.         $this->username = $_SESSION['username'] = $user->username;
  21.  
  22.  
  23.         $this->user_id = $_SESSION['user_id'] = $user->id;
  24.         $this->signed_in = true;
  25.         }
  26.     }
  27.  
  28. //********************* the test.php page*******************//
  29.  
  30.  
  31. <?php include("includes/init.php"); ?>
  32.  
  33. <?php if(!$session->is_signed_in()) {redirect("login.php");} ?>
  34.  
  35. <?php
  36.  
  37. if(isset($_POST['submit'])){
  38.         echo "first name is ". $_SESSION['first_name']."<br>";     
  39.         echo "Username is ". $_SESSION['username']."<br>";
  40.         echo "User id is ".$_SESSION['user_id']."<br>";
  41.        
  42. }
  43.  
  44. ?>
  45.  
  46. <!DOCTYPE html>
  47. <html lang="en">
  48. <head>
  49.     <meta charset="UTF-8">
  50.     <title>Document</title>
  51. </head>
  52. <body>
  53.  
  54.     <form action="" method='post'>
  55.         <input name='user' type="text">
  56.         <input name='submit' type="submit">
  57.     </form>
  58.    
  59. </body>
  60. </html>
  61.  
  62. //******************* the return******************//
  63. Notice: Undefined index: first_name in C:\xampp\htdocs\gallery\admin\test.php on line 13
  64. first name is
  65. Username is william
  66. User id is 190
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement