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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

[noob]Php Sessions

  • 27-07-2012 11:45am
    #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, Registered Users 2 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