php - Session data not being passed through to the next page -


i have login system has 2 pages, it's quite simple doesn't appear data being passed through being redirected back. have tried couple solutions. adding exit; , die; after inital redirect login. have printed session_id worked fine.

login page:

session_start();  if(isset($_post['login'])){     $username = strip_tags($_post['username']);     $password = strip_tags($_post['password']);      $username = stripslashes($username);     $password = stripslashes($password);      $password = md5($password);      $sql = "select * table username = :username limit 1";     $stmt = $conn->prepare($sql);     $stmt->bindparam(":username", $username);     $stmt->execute();     foreach($stmt $row) {         $id = $row['id'];         $db_password = $row['password'];     }      if($password == $db_password){         $_session['username'] = $username;         $_session['id'] = $id;         header("location: admin.php");         exit;     }else{         echo "you did not enter correct details.";     } } 

this admin page. redirects login , doesn't further down page

session_start();  if(!isset($_session['id'])){     header("location: login.php"); } 

execute()

returns true on success or false on failure.

you need fetch data form result set as

 $stmt->execute();  $row = $stmt->fetch(pdo::fetch_assoc);// fetch data  $id = $row['id'];  $db_password = $row['password'];  if($password == $db_password){// compair     $_session['username'] = $username;     $_session['id'] = $id;     header("location: admin.php");     exit; }else{     echo "you did not enter correct details."; } 

Comments

Popular posts from this blog

gridview - Yii2 DataPorivider $totalSum for a column -

java - Suppress Jboss version details from HTTP error response -

Sass watch command compiles .scss files before full sftp upload -