www.webdeveloper.com
+ Reply to Thread
Results 1 to 10 of 10
  1. #1
    Join Date
    Nov 2010
    Posts
    63

    PHP session does not always start?

    I have a PHP page called adminConnect.php, it has a session start as its first line, some includes and some functions. One of those functions is "ValidateLogin()", it will auto redirect the user to the homepage when the user does not have any sessions.

    Here is the weird problem: Less then 1% of the time (when the page changes) my ValidateLogin wont detect the session and will redirect me to the homepage. If I hit back the page will load fine (the same function will be called) and ill be able to continue using my system.

    Here is the start of the function that kicks me out < 1% of the time (ive confirmed it with the error_log line):

    Here is the function (the echo should never be seen)
    Code:
    if (!(isset($_SESSION['csmsConnected'])))
    		{
    			error_log("csmsConnected session not set trigged. It should of auto redirected the user to the home page");
    			echo('<br/><h1 style="text-align: center">Error, you must be logged in to view this page.</h1>'); // user should never see this
    			header('Location: login.php');
    			exit();
    		}
    Ideas? Between it appearing to happen randomly + it happening so few times I haven't been able to figure this one out. Its almost like my session_start(); isn't registering.

  2. #2
    Join Date
    May 2012
    Posts
    37
    Your "if" statement is a little weird... not sure if it's the cause but try it with:
    PHP Code:
    if (!isset($_SESSION['csmsCOnnected'])) { //the rest } 
    You could also try using empty() - depending on how csmsConnected is initialized, isset may not give the expected result:

    PHP Code:
    $test "";

    if (!isset(
    $test)) {
        echo 
    'not set';
    } else {
        echo 
    'is set';
    }

    //output: is set 
    Using empty() will check for empty strings.
    "A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools."
    -- Douglas Adams

    http://www.chaoscontrol.org
    Have you minified your CSS/JS lately?

  3. #3
    Join Date
    Nov 2010
    Posts
    63
    Here is the error I get:
    PHP Warning: session_start() [<a href='function.session-start'>function.session-start</a>]: open(C:\php\sessiondata\\sess_k454, O_RDWR) failed: Permission denied (13) in
    I noticed this error both when from going from page to page and when my ajax checks to see if a user is still valid. Once again this might only happen 1 in 100 times.

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    18,049
    It's telling you that the process running PHP does not have permission to write the data to the session directory/file on the disk. As to why it would only do that once in awhile, I have no idea. But take a look at the permissions/setting on the C:\php\sessiondata directory and see if anything catches your attention.
    "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
    Jul 2012
    Location
    Vancouver
    Posts
    55
    Sounds like it's a swap/tmp directory size issue - garbage collection isn't keeping up with server usage

    If it was a permission issue it would happen all the time

  6. #6
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    18,049
    Quote Originally Posted by mistin.ca View Post
    Sounds like it's a swap/tmp directory size issue - garbage collection isn't keeping up with server usage

    If it was a permission issue it would happen all the time
    Good point. Sounds like something to look into.
    "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

  7. #7
    Join Date
    Nov 2010
    Posts
    63
    How would I look into that? This server has more than enough space and im not aware of anything that puts a constraint on the temp folder or anything. That also would not explain how it never happens two times in a row (in other words, if it was a size issue, what are the odds that in the 5s or so it takes me to hit back, it would be resolved 100% of the time?)

    I am thinking of maybe upgrading PHP to latest version. But this is a live server, so I do not want to mess with it too much.

  8. #8
    Join Date
    Aug 2012
    Posts
    8
    Code:
    if (!(isset($_SESSION['csmsConnected'])))
    One too many brackets there
    should be
    Code:
    if (!isset($_SESSION['csmsConnected']))


    -FS Designs

  9. #9
    Join Date
    Oct 2009
    Posts
    658
    Quote Originally Posted by FSDesigns View Post
    Code:
    if (!(isset($_SESSION['csmsConnected'])))
    One too many brackets there
    should be
    Code:
    if (!isset($_SESSION['csmsConnected']))


    -FS Designs
    Now now I have to try this myself. Didn't realize up to now that too many groupings is a factor

    What version of PHP are you using by the way? Is this standard install or you guys compile this yourselves? On php.ini you'll see settings for sessions perhaps you can play with it as to why you have "\\" on the session path.
    Good Luck

    Santos Systems

  10. #10
    Join Date
    Jan 2009
    Posts
    3,341
    Just out of curiosity is it possible that you might be switching domains between requests? Such as www.adomain.com with one request and then adomain.com for another? I have had some seemingly random session dropping due to that in the past.

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