Bonjour,

I have the following script stored in a Linux server:

<?php
//---------------------session.php------------
session_start();
echo session_id();
?>

Executing the script inside the server itself using "/usr/bin/php session.php" simply returns different session ID each time. To my understanding, it is because of I don't use browser to access the page. So is there a way to retain the session ID via php command line??

    janhouse00;10928589 wrote:

    Bonjour,

    I have the following script stored in a Linux server:

    <?php
    //---------------------session.php------------
    session_start();
    echo session_id();
    ?>

    Executing the script inside the server itself using "/usr/bin/php session.php" simply returns different session ID each time. To my understanding, it is because of I don't use browser to access the page. So is there a way to retain the session ID via php command line??

    In short, you are right. Here is the long answer. The browser stores the session as a session cookie in the browser. When you use sessions with CLI, there is nothing to store the session information which means everytime you execute the script it is creating a new session.

      if your server has a browser that supports sessions you could use that. What are you trying to do that requires sessions in a script called from the command line?

        Thanks for the clarification, my idea is rather plain illogical: I have a daily CRON script that generates/depends on an auto-increment value, so I tried session just because I want to get rid of text file and database and stuff =)

          Write a Reply...