Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Weird empty session issue

Status
Not open for further replies.

Borvik

Programmer
Jan 2, 2002
1,392
0
0
US
Ok - first I've confirmed sessions working with this test script:
Code:
<?php 
session_start(); 
if (!isset($_SESSION['counter'])) $_SESSION['counter']=0;
echo "Counter ".$_SESSION['counter']++." ???.<br><a href=".$_SERVER['PHP_SELF'].">reload</a>"; 
?>
However when I'm using my code it doesn't work in Chrome or Safari but does work in FireFox, IE8, and Opera.

At the end of my code I put:
Code:
        echo session_id(); echo '<pre>'; var_dump($_SESSION); echo '</pre>';
        session_write_close(); exit();
I am seeing the session data in the browser. At this point I go to the server and I can find the session file - but it is empty (though only when I'm using Safari or Chrome). Any ideas as to what might be causing it to not save the session data?

Thanks.
 
Forgot running PHP 5.2.6 on Windows NT PDP-IIS 5.2 build 3790.
 
make sure that you have error reporting and display errors turned on.
the most likely reason for the issue is that either php cannot find where to store the session files or it does not have the permission to write to that destination. error_reporting and display_errors should give you this information (or you could just check the php.ini file ...)

remember on windows you need to give the web process's user write perms to th e session directory. tpyically this is IUSR_MACHINENAME
 
This is the top of the file:
Code:
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
session_start();

I can find the session files just fine - the sessions are getting written (for the test page).

More testing has revealed that it won't save a particular session variable.

Here is the output of var_dump($_SESSION):
Code:
array(3) {
  ["test"]=>
  string(5) "other"
  ["tester"]=>
  bool(false)
  ["saved_form"]=>
  array(1) {
    ["dgvSJM"]=>
    array(4) {
      ["method"]=>
      string(4) "post"
      ["processor"]=>
      string(0) ""
      ["formid"]=>
      string(10) "searchForm"
      ["fields"]=>
      array(2) {
        ["searchTerm"]=>
        array(5) {
          ["label"]=>
          string(10) "SearchTerm"
          ["type"]=>
          string(6) "search"
          ["required"]=>
          bool(false)
          ["multiple"]=>
          bool(false)
          ["selectempty"]=>
          string(6) "B5BMXw"
        }
        ["formInput_0"]=>
        array(5) {
          ["label"]=>
          string(0) ""
          ["type"]=>
          string(6) "submit"
          ["required"]=>
          bool(false)
          ["multiple"]=>
          bool(false)
          ["selectempty"]=>
          string(6) "TkZUfo"
        }
      }
    }
  }
}
Of all that - only the first two session variables (test, tester) are showing up in the session file on the server.
 
a race condition? what happens if you wait five seconds before hitting the link?
 
I'm no longer hitting a link in my testing.

As soon as the page displays the session information from var_dump (followed by session_write_close and exit), I am going to the server and opening up the session file (from the ID displayed.

The file shows test and tester with the appropriate values but not the saved_form variable. I can wait a while before checking the session file, but waiting doesn't change it. It is still showing just the test variables after the wait.
 
Odd thing is only is certain browsers so the server side should be ok.
Borvik - Your test code in post #1, does that only try to save the session variable? and does that work consistently with the browsers you mentioned?
Interesting your failing browsers are both WebKit based - msybe a red herring.
 
The code in Post #1 (first code block) was only to test the session variable - and it works on all the browsers mentioned.

The second code block in Post #1 was my attempt to make sure SOMETHING was in the session right before the script exited, which appears to be the case in all browsers.

I thought it might be a WebKit based thing - but that doesn't make much sense as the saving of the session is done on the server. And it especially doesn't make as much sense after I added some simple session variables to my code and those saved - but the array did not.
 
The saved_form keys and the selectempty values are random - so these change on every page refresh (nonce values).

Ok - I closed FireFox and reopened it.

After the first page load, the new session file only has the test and tester values in it.

Once I hit refresh those random values change - but the session file on the server now has all the data saved in it - with the correct random values as well.
 
Refresh did not help the WebKit browsers.
 
Ok, another weird thing about this.

I've changed my testing code to be this:
Code:
        $arr = $_SESSION['saved_form'];
        unset($_SESSION['saved_form']);
        $_SESSION['testarr'] = $arr;
        echo session_id(); echo '<pre>'; var_dump($_SESSION); echo '</pre>';
        session_write_close(); exit();
Close and open my browser to get a new session - and open up the corresponding session file on the server, testarr shows up as properly saved.

I have 'saved_form' being created from an included file (for the class) and another included file utilizing the class. I can't imagine that being the cause - as it's only happening with a couple of browsers. In fact I can't imagine how it could possibly be linked to the browser - I would bet on a server-side problem, maybe configuration - or code issue, but something just doesn't add up.
 
I created another website within IIS and copied the code over to it using a different subdomain. So it's the exact same environment as the other one.

Guess what it works - bizarre huh?

So I tried deleting the original website, and recreating it - with no luck. Then I tried saving the working sites config to a file and then deleting the original website and creating a new site from the working config. It still didn't work.

If someone could explain this - awesome, I haven't a clue as to what is going on here.
 
It does sound really odd especialy the copying bit on your last post.
The odd thing with the browsers is they might be sending the session and cookie information in different ways. IIS has a history of odness in this area.
Have to have a think about some diagnostics on this one.
Have you comer accross tool called Fidler2?. It's a free microsoft product which captures the HTTP traffic for analysis. If you could look at that and maybe install it?
 
If anything it would be in the REQUEST headers being sent to the server, causing the server to do something different.

I've got the results of Fiddler for the working site (omega), and the non-working site (theta) using Chrome.

Code:
GET / HTTP/1.1
Host: omega.website.com
Connection: keep-alive
Cache-Control: max-age=0
Accept: application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.237 Safari/534.10
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Cookie: __utmz=171396961.1294152275.70.3.utmccn=(organic)|utmcsr=google|utmctr=[URL unfurl="true"]http://website.com/|utmcmd=organic;[/URL] __utma=171396961.840020302.1247673206.1294694811.1294948538.72

HTTP/1.1 200 OK
Connection: close
Date: Wed, 26 Jan 2011 15:59:53 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-Powered-By: PHP/5.2.6
Set-Cookie: PHPSESSID=oolo4ilbkvuenhca7iupqqnrq1; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-type: text/html
Code:
GET / HTTP/1.1
Host: theta.website.com
Connection: keep-alive
Cache-Control: max-age=0
Accept: application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.237 Safari/534.10
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Cookie: __utmz=171396961.1294152275.70.3.utmccn=(organic)|utmcsr=google|utmctr=[URL unfurl="true"]http://website.com/|utmcmd=organic;[/URL] __utma=171396961.840020302.1247673206.1294694811.1294948538.72

HTTP/1.1 200 OK
Connection: close
Date: Wed, 26 Jan 2011 15:55:56 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-Powered-By: PHP/5.2.6
Set-Cookie: PHPSESSID=j1jlfolo3q1me9f46o33qumba4; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-type: text/html
This was after I cleared all cookies for each site. They look pretty much identical. This might be an IIS issue - though I'm not sure why recreating the site didn't work. I wish I could completely get rid of IIS - but the boss like to edit the page using FrontPage, so we are sticking with IIS.
 
what is the link between frontpage and IIS? (not having used either for many years).
 
FrontPage Extensions that allows you to edit a page live on the server.
 
Frontpage is as old as the hills !, Do you use FP to upload the site via the extentions?
You can instal Frontpage extentions on Unix, I would look into that if Unix will solve your issue. Can you try it out on a Unix server ?
This isn't the first we've had odd session issues. Is there any chance you could write the sessions to a database rather than the file system
 
re frontpage, that is what I was going to say.

frontpage 'live editing' is, i thought, essentially just via webdav.
 
@ingresman - "can install FrontPage extension on Unix"? (would use Linux here rather than Unix) - I've looked into that before but was unable to find anything appropriate - perhaps you can point me towards something?

We don't actually use the FrontPage program anymore - it has upgraded to Expression Web - same technology backend from what I understand.

I have a website that does use session storage in a database, but something was going on with it that made me reconsider the file system (I think there was some weird concurrency issues with some dynamic images). I may have to revisit database storage again and how to integrate that into my MVC framework.
 
re: frontpage - it is actually more than just live editing, I think it also has something to do with link checking, site templates, shared borders, etc... I'm trying to ween the boss off of it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top