Having problems with sessions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

In IE I don't see anything
That's because I'm still unable to put a valid </title> in the code, grmpf.

Code: Select all

<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
session_start();
?>
<html>
	<head>
		<title>session test</title>
	</head>
	<body>
		<p><?php echo 'time: ', date('H:i:s'); ?></p>
		<p><?php echo 'id:', session_id(); ?></p>
		<p><?php echo 'name:', session_name(); ?></p>
		<p><?php echo 'use_cookie: ', ini_get('session.use_cookies'); ?></p>
		<p><?php echo 'use_only_cookie: ', ini_get('session.use_only_cookies'); ?></p>
		<p><?php echo 'session.use_trans_sid: ', ini_get('session.use_trans_sid'); ?></p>
		<pre><?php print_r($_COOKIE); ?></p>
				
		<div><a href="<?php echo $_SERVER['PHP_SELF']; ?>">reload</a></div>
	</body>
</html>
Array
(
)
There should have been a cookie PHPSESSID, but there isn't. The browser does not send any cookies back to the webserver. Therefore php does not know anything about a previously started php session
Stephen Bungert
Forum Commoner
Posts: 25
Joined: Sat Feb 25, 2006 3:22 am

Post by Stephen Bungert »

But I can save and make cookies with PHP. I've used them before.

And my browser accepts cookies too.

Should I re-install PHP and Apache?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

What does the "latest" version of the script -including error_reporting, ini_set- print?
Again reload the script several times using the link.
Stephen Bungert
Forum Commoner
Posts: 25
Joined: Sat Feb 25, 2006 3:22 am

Post by Stephen Bungert »

In IE I see the following:
time: 22:57:59

id:2tu7e6hctbkos9ur43dmiu07k6

name:PHPSESSID

use_cookie: 1

use_only_cookie: 0

session.use_trans_sid: 0

Array
(
)


reload
Firefox displays the same too.

The only thing that seems to change is the session id
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

hm, still no cookie.
Let's try to set one manually.

Code: Select all

<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
// this should appear in _COOKIE after a reload
setcookie('mycookie', date('H:i:s'));
session_start();
?>
<html>
	<head>
		<title>session test</title>
	</head>
	<body>
		<p><?php echo 'time: ', date('H:i:s'); ?></p>
		<p><?php echo 'id:', session_id(); ?></p>
		<p><?php echo 'name:', session_name(); ?></p>
		<p><?php echo 'use_cookie: ', ini_get('session.use_cookies'); ?></p>
		<p><?php echo 'use_only_cookie: ', ini_get('session.use_only_cookies'); ?></p>
		<p><?php echo 'session.use_trans_sid: ', ini_get('session.use_trans_sid'); ?></p>
		<pre><?php print_r($_COOKIE); ?></p>
	           
		<div><a href="<?php echo $_SERVER['PHP_SELF']; ?>">reload</a></div>
	</body>
</html>
Stephen Bungert
Forum Commoner
Posts: 25
Joined: Sat Feb 25, 2006 3:22 am

Post by Stephen Bungert »

time: 23:04:58

id:ak2s2n5sgg03gb5ufr4q462351

name:PHPSESSID

use_cookie: 1

use_only_cookie: 0

session.use_trans_sid: 0

Array
(
[mycookie] => 23:04:58
)


reload
Again only session id changes (and the time and cookie time)
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

I suggest deinstalling apache,php,mysql,whatever and using http://www.apachefriends.org/en/xampp.html
Stephen Bungert
Forum Commoner
Posts: 25
Joined: Sat Feb 25, 2006 3:22 am

Post by Stephen Bungert »

OK, thanks all for your help... pain in the arse to reinstall but I guess I must.


Thanks all again. I shall post back if re-installing helped.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

installing xampp only takes a minute.
Stephen Bungert
Forum Commoner
Posts: 25
Joined: Sat Feb 25, 2006 3:22 am

Post by Stephen Bungert »

I have it installed now xampp, but I can't find the apache config file there is none. I need to have it set up the way it was before (I still have the old config file. Where the old config file used to be (in the apache directory under xampp) there is only the default config file example. Where's the actuall config file being used by apache?
Stephen Bungert
Forum Commoner
Posts: 25
Joined: Sat Feb 25, 2006 3:22 am

Post by Stephen Bungert »

Found it.

Also sessions now working with xampp installed


Thanks all for your help
:D
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Glad you got it working.
Post Reply