I'm use sessions in 2 pages. In the first, page one, I save data to it:
page one code :
<?php session_start(); $_SESSION['dl']="goooo"; // run page two by use fsockopen ...
In page two:
<?php session_start(); $_SESSION['dl']="asd"; ...
When I read the session in the other page result is "goooo"! Why is "asd" not saved to the session?
what is your idea for save 'dl' in multi page??? (post and cookie is not helpfull)
Because fsockopen is not sending back the cookie that identifies the browser to your server.
Try to have three pages and do the same experiment. You'll see that they will work out as expected.
Because a session is effectively a serialised array that is identified by a number. The number that allows PHP to load the right session is sent via cookie (or URL parameter) from the browser of the user. If you're opening page two with fsockopen
, you're presumably not providing the right session ID. As such, a new session is created in that call (and forgotten about, as noone knows the number).
Moreover, $_SESSION
is not reloaded during the execution of one page - it assumes a page execution is one request from a browser, and so won't be magically changed in the middle of the request.
Sessions work by saving a session ID in a cookie on the client browser. It doesn't surprise me that sessions don't work when you run a script using fsockopen
, practically opening the page on the server instead of the client browser.