Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

[noob]Php Sessions

Options
  • 27-07-2012 12:45pm
    #1
    Closed Accounts Posts: 183 ✭✭


    Hi folks,

    I'm doing a spot of work on a fansite I'm making for my faveourite television show and I wanna use sessions in PHP. I'm having a problem with passing variables to another page.

    so, on the first page I have something like:

    session_save_path('/folder'); session_start();
    $sesid=rand(10000,50000);
    session_id($sesid);
    $var='Example'
    $_SESSION=$var;
    $_SESSION=$sesid;


    $var is just some example of a variable that I make up.
    everything works fine on the first page. but on the second page I have the following:


    session_save_path('/folder'); session_start();
    $path='/folder';
    ini_set('session.save_path', $path);
    $var=$_SESSION;
    $sesid=$_SESSION;
    session_id($sesid);

    on this page then I get an error of the form...

    Warning: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/folder) in Unknown on line 0


    I've tried a few different things like moving making sure I've no white spaces, trying different folders, getting rid of the sesid thingy and so on.

    Has anyone encountered this before?
    Thanks


Comments

  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    Lines 2 & 3 in the second script are redundant. You've already set the session path, so you don't need to set it again.

    In fact you're probably getting an error because you're trying to change the session path after you've opened the session.

    Delete these two lines of code:

    $path='/folder';
    ini_set('session.save_path', $path);

    Then try again.


  • Closed Accounts Posts: 183 ✭✭pvt6zh395dqbrj


    Thanks, I tried that.

    Same problem I'm afraid...


  • Closed Accounts Posts: 7,145 ✭✭✭DonkeyStyle \o/


    Why don't you just do:
    [php]
    <?php
    //page 1
    session_start();
    $_SESSION = 'something';
    ?>
    [/php]
    [php]
    <?php
    // page 2
    session_start();
    echo $_SESSION;
    ?>
    [/php]
    Unless you're trying to do something special with the session id, why not let php manage it?
    If you echo the session_id() without setting it explicitly, you'll see it already has a lot more entropy than rand(10000-50000).


Advertisement