mysql - $_SESSION is not passing values between pages php -


i have 3 files. (loginfunctions.php , login.php , index.php) in login.php, take values , pass loginfunction.php check values , select userid prepared statement return login.php. after login.php calls method called (get('value')) pass userid , return user info. started session in login , index pages. tried echo info have been stored in session nothing returning.

my codes:

loginfunction.php

<?php  function absolute_url($page = 'index.php') {     //header('location: http:\\localhost');     //exit(); //terminates script      $url = 'http://' . $_server['http_host'] . dirname($_server['php_self']);     $url = rtrim($url, '/\\');     $url .= '/' . $page;      return $url; }  function checklogin($email = '', $password = '') {     $errors = array();      if (empty($email)){         $errors[] = 'you must enter email';     }     if (empty($password)){         $errors[] = 'you must enter password';     }     if (empty($errors)) { ////set database econnection         require_once 'do_classes/mysqli_connect.php';          $db = new database();         $dbc = $db->getconnection();          $stmt = $dbc->prepare("select user_id user user_email=? , aes_decrypt(user_password, 'p0ly')=?");          if ($stmt) {             $stmt->bind_param('ss', $email, $password);              if ($stmt->execute()) {                 $stmt->store_result();                 $stmt->bind_result($user_id);                 $stmt->fetch();                 $stmt->close();                 if(!empty($user_id)){                     return array(true, $user_id);                 }else{                     /*                      * <div class=\"alert alert-success alert-dismissable\">                                 <button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">&times;</button>                                 invalid email or password                             </div>                      */                     $errors[] = '<div class="alert alert-danger alert-dismissable">                                 <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>                                 <p align="center">invalid email or password</p>                             </div>';                 }              } else {                 $errors[] = 'passwords not match';             }         }else {             echo '<p class="error"> oh dear. there databse error</p>';             echo '<p class = "error">' . mysqli_error($stmt) . '</p>';         }     }     return array(false, $errors); }  ?> 

login.php

<?php if (isset($_post['submitted'])) {     //require_once similar 'include' ensures code not copied multiple times     require_once('functions/loginfunctions.php');      //list() way of assigning multiple values @ same time     //checklogin() function returns array list here assigns values in array $check , $data      list($check, $data) = checklogin($_post['email'], $_post['password']);       if ($check) {         //setcookie('fname', $data['fname'], time()+ 900 ) ;  //cookie expires after 15 mins         //setcookie('lname', $data['lname'], time() + 900 ) ;           session_start();         require_once 'classes/do_users.php';         $user = new do_user();         $user->get($data);         //use session variables instead of cookies         //these variables should available pages in application long users session exists          $_session['userid'] = $user->userid;         $_session['usertype'] = $user->usertypeid;         $_session['last_activity'] = time(); //your last activity now, having logged in.         $_session['expire_time'] = 60 * 5; //expire time in seconds: 3 hours (you must change this)         //to enable $_session array populated need call start_session() - done in header.php         //print_r print out contents of array         //print_r($_session);           //         //redirect page          $url = absolute_url('index.php');  //function defined in loginfunctions.php give absolute path required page         //this version of header function used redirect page         header("location: $url"); //since have entered correct login details being directed home page         exit();     } else {         $errors = $data;     } }   if (!empty($errors)) {     //foreach simplified version of 'for' loop     foreach ($errors $err) {         echo "$err <br />";     }      echo '</p>'; }  //display form ?>  

in index.php, called require_once 'header.php'; has session_start(); nothing returning, why?

i found problem, because prepared statement. prepared statement wasn't working because declaration of prepared statement has missing values.


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -