1

I'm develop a hybrid application and it will using PHP sessions to save user information. In my case, I tried to used php sessions to save the data, but it doesn't save. And then, to testing in web, the result var is show saved.

Here is my example:

<?php
session_start();
if(isset($_POST["Token"])){
    $token = $_POST["Token"];

    if (isset($_SESSION['device_token']) && $_SESSION['device_token']) {
        $token = $_SESSION['device_token'];
    } else {
        $_SESSION['device_token'] = "notoken";
    }
}
?>

Here is my PHP info:

My php Info 1

My php Info 2

Edit:

<?php
ini_set('session.save_path',$_SERVER['DOCUMENT_ROOT'] .'/phpVar');
session_start();

if(isset($_POST["Token"])){
$token = $_POST["Token"];
$_SESSION['device_token'] = $token;
}
if(isset($_GET['ID'])){
$token = $_SESSION['device_token'];
$member_id = $_GET['ID'];
$_SESSION['ID'] = $member_id;

echo $_SESSION['device_token'] ;
echo $_SESSION['ID'] ;
}
?>
Diem Wu
  • 11
  • 2
  • maybe [this](http://stackoverflow.com/questions/155920/php-session-data-not-being-saved?rq=1) help you. – SdSaati Jul 14 '16 at 05:01

1 Answers1

0

because you missed the }

so, instead of:

if(isset($_POST["Token"])){
    $token = $_POST["Token"];

should be:

if(isset($_POST["Token"])){
    $token = $_POST["Token"];
}

EDIT

Ok, then try to see whether you session directory is writable:

if (!is_writable(session_save_path())) {
    echo "No, it's not. Path:".session_save_path(); 
}
else{
    echo "yes, it's writable";
}

EDIT

when path is not set, you might set it manually just before session_start

ini_set('session.save_path',getcwd(). '/tmp');

and afterwards you need to create tmp folder and give it right permission

Marko Krstic
  • 1,417
  • 1
  • 11
  • 13
  • Thank for your help! HAHA, because it is not copy from my source.. maybe have some missing~ – Diem Wu Jul 14 '16 at 04:06
  • i can see the session in folder(tmp), but i can't get the var – Diem Wu Jul 14 '16 at 08:47
  • how do you mean "i can't get the var"? What's the result of echo $_SESSION['device_token']? – Marko Krstic Jul 14 '16 at 08:51
  • the mean is cannot get the session var to use. echo $_SESSION['device_token'] is print noting – Diem Wu Jul 14 '16 at 09:03
  • can you re-post all your code, to see how it looks? – Marko Krstic Jul 14 '16 at 09:06
  • Ok, posted. When i finished the post method, the next step is loading get method. but i can't in get method to use session token. – Diem Wu Jul 14 '16 at 09:17
  • you are making it complicate now. Let's first see whether sessions work by you or not. Remove everything and write only ini_set('session.save_path',$_SERVER['DOCUMENT_ROOT'] .'/phpVar'); session_start();$_SESSION['te'] = 12;echo $_SESSION['te']; – Marko Krstic Jul 14 '16 at 09:49