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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

session_start() problem

Status
Not open for further replies.

Masali

Programmer
Joined
Jun 19, 2002
Messages
143
Location
SE
Hi,

I am trying to use session_start() but there is no cookie written. What can be the problem? The header that I get from the script is:

Code:
HTTP/1.1 200 OK
Date: Wed, 03 Dec 2003 17:05:13 GMT
Server: Apache/1.3.26 (Unix) PHP/4.2.2
X-Powered-By: PHP/4.2.2
Set-Cookie: PHPSESSID=705f6e9d103bd14781e71403f5ef8980; 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
Connection: close
Content-Type: text/html

As you see the cookie seems to be there but it isn't saved. Cookies are turned on in the browser. I wonder what the expires header is? That seems to be rather old...

 
The cookie is being sent. How are you verifying that the cookie is not saved?


Typically, a pair of scripts like these is a good way to test basic session functionality:

set_session.php:
Code:
<?php
session_start();
$_SESSION['foo'] = 'bar';

print '<html><body><a href=&quot;get_session.php&quot;>click here</a></body></html>';
?>

get_session.php:
Code:
<?php
session_start();

print $_SESSION['foo'];
?>

Want the best answers? Ask the best questions: TANSTAAFL!!
 
I faced the same problem some time ago. Even on the computers with cookies turned on I wasn't able to use them. Fortunately, php can pass the session ID also through the URL and it will do it for you automatically in case it can't use cookies ;-). Go to php.ini if you would like to change the behaviour of the sessions.
 
It is important, also, to know that a cookie is not available on the page that saved the cookie. I don't know if this is applicable to you in this case, but it can relieve frustration.

In other words, if you set a cookie on a page, you can't read it until you refresh or go to another page and then read it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top