1

I try to create a session to be available for PHP pages.

But it is not working.

Test1.php

session_start();
$_SESSION["current_id"] = 7 ;

echo "Current id : " .  $_SESSION['current_id'] . "</br>" ;
if (!is_writable(session_save_path())) {
    echo 'Session path "' . session_save_path() . '" is not writable for PHP!'; }
else {
    echo 'Session path "' . session_save_path() . '" is Writable for PHP!'; } 
echo("</br>");    
var_dump($_SESSION);

Result:

Current id : 7
Session path "/var/lib/php5" is Writable for PHP! /home/ubuntu/workspace/CRF/main1.php:58: array(1) { 'current_id' => string(1) "7" }

Tets2.php

session_start();
echo "Current id : " .  $_SESSION['current_id'] . "</br>" ;
echo("</br>");    
var_dump($_SESSION);

Result:

Current id : /home/ubuntu/workspace/CRF/workflow.php:108: array(0) { }

Any Ideas?

Peyman Mohamadpour
  • 17,954
  • 24
  • 89
  • 100
Konstantin111
  • 219
  • 1
  • 3
  • 12
  • That code should give you some serious syntax errors. You're not closing the php tag after `$_SESSION["current_id"] = 7 ;` while opening a new one two lines down. _Tip:_ If you have a block of code, have _one_ open php tag and then _one_ close tag after all the code, don't open and close it per command. – M. Eriksson Feb 23 '17 at 15:27
  • Thank you. Off course the block is closed. It's lost when I copy code. Sorry. – Konstantin111 Feb 23 '17 at 16:34
  • Thank you justbaron . It's not a duplicate question. I put on the first line of the pages. – Konstantin111 Feb 23 '17 at 16:36
  • You should give more information since _not working_ is very general. – Nicolas Feb 23 '17 at 18:16
  • Hi Nicolas, thank you for your comment, not working is mean session variable not available in any pages except where it was initialized. – Konstantin111 Feb 23 '17 at 18:45
  • turn on [error logging on your page](http://stackoverflow.com/questions/6587515/how-to-display-php-errors-in-code-output). What does that tell you? – Martin Feb 27 '17 at 17:00
  • @justbaron no, not a duplicate of that question. Read the qustions! – Martin Feb 27 '17 at 17:02
  • @Konstantin111 have you checked all the replies and potential issues [raised here](http://stackoverflow.com/questions/6200612/session-variables-are-not-persisting-between-page-loads)? – Martin Feb 27 '17 at 17:04

0 Answers0