tags:

views:

238

answers:

4

i am using php 5.2.8

i have index.html, which loads LOAD.PHP from IFRAME.

iframe src="load.php".....

i printed out load.php's session id.

then i ran another test.php, and printed out it's session id.

php session id's were different.

therefore, i cannot pass any session variables....

what is happening here ? this problem did not happen before, suddenly today it started happening.... however this problem still exists....its driving me nuts !

session.saved_path is same for both.... /var/php5, cookie path is same...

A: 

(not really an answer as your questions doesn't seem to me to have enough data to provice a certain answer, but rather a few things to check about)

The files are in the same domain and directory and the cookie are not limited to a different directory (i.e. path=/)? (note: they're not limited unless you tell that explicitly with session_set_cookie_params )

Is the browser sending the cookie (or are you maybe in "incognito mode")? If cookies don't work PHP will probably try to pass Session IDs in the QueryString and fail, if you go to test.php writing its name manually and not following a link (usually I use session.use_only_cookies=1 to avoid that).

lapo
+1  A: 

If PHP is creating a second session ID on the second load of the page, then it means that the first one was not passed back properly. Likely, the cookie is not being set for some reason. Things to check:

  • Test in multiple browsers?
  • Did you disable cookies in your browser somehow?
  • Is the iframe on a different domain or subdomain that might prevent cookie passing?
  • Install LiveHTTPHeaders or some other firefox add-in to check the cookies you are receiving
zombat
point 3 is true of course :)
AlberT
A: 

http://www.example.com will have a different sessionID than http://example.com

Quamis
bit surprised why my web app complained about this earlier....anyways this did the trick, the iframe was loading something without www.
This is true, but it is not the root of the problem.
AlberT
A: 

They will have different SID if they have different cookie domain or cookies are not working at all and PHP is configured to use only cookies for session ID (session.use_only_cookies=1).

Cookies domain is explained here

Only hosts within the specified domain can set a cookie for a domain and domains must have at least two (2) or three (3) periods in them to prevent domains of the form: ".com", ".edu", and "va.us". Any domain that fails within one of the seven special top level domains listed below only require two periods. Any other domain requires at least three. The seven special top level domains are: "COM", "EDU", "NET", "ORG", "GOV", "MIL", and "INT".

The default value of domain is the host name of the server which generated the cookie response.

So set a common domain for your hosts and they will share cookies, thus PHP SID :)

AlberT