www.webdeveloper.com
+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2012
    Posts
    3

    Exclamation session_start() is not working on command line

    Hello,
    I have worked with session variable. I got one issue can you please tell me the solution of that. I have created two script in which I have used session variable I will send my script to you.

    /******** Input.php *********/
    <?php
    session_start();
    var = 50;
    $_SESSION['var'] = var;
    ?>

    /********** Output.php **********/

    <?php
    session_start();
    print $_SESSION['var'];
    ?>

    when I execute both of the script by using browser ("http://localhost/Input.php" then "http://localhost/Output.php" ) its work according to the code. But when I execute it with command prompt ("php Input.php" then "php Output.php") then is gave output

    Undefined index: var in /usr/local/apache2/htdocs/Output.php
    I searched for this problem and found that session_start() is not work with command prompt. Can you please tell me the solution for that.

    Thanks and Regard,
    Antrikssh...

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    18,041
    I doubt it will work via the command line like that, since it would depend on the command line interface to pass in the session ID cookie. You would need some way for the first script to pass the session ID to you, so that you could add it as a command line argument in the second script and apply it, allowing session_start() to know which session data file to open.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Aug 2012
    Posts
    3
    I found the solution of my problem, due to different session id command line and browser unable to communicate with each other. If there is any way to send session id to my client script and my client script run by using that session id.

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    18,041
    If you pass the session ID as a command line argument, you should be able to use it something like:
    PHP Code:
    <?php
    if(!empty($argv[1])) {
      
    sesssion_id($argv[1]);
      
    session_start();
    }
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    Aug 2012
    Posts
    3
    Hello,
    thanks for your support, I have used server session_id and pass it to only one script that I executed through browser. After that All the script run by using that id only. But every time when I start the server it session id will change and I have to configure that id with that script. This problem I will manage but the main problem is that when I used while(1) in my server script it run according to the code inside the loop on server side console but, when I access the data from client script that time client script is in wait mode until the server script is not terminate. This is very big problem that I have faced after all this struggle.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



Recent Articles