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
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Is javascript turned on for your computer?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Code: Select all

<?php session_start(); ?>
<html>
	<head><title>session test</head>
	<body>
		<?php echo 'time: ', date('H:i:s'), ' | id:', session_id(); ?>
		<br />
		<a href="<?php echo $_SERVER['PHP_SELF']; ?>">reload</a>
	</body>
</html>
If you click the link to reload the page does only the time change or the id as well?
Stephen Bungert
Forum Commoner
Posts: 25
Joined: Sat Feb 25, 2006 3:22 am

Post by Stephen Bungert »

Yes, JavaScript is on. I use it all the time.

volka, Your script shows an empty page. Not even the title is in the title path of the browser, just the actuall physical path on the server: 'http://localhost/php_test_2.php'
Stephen Bungert
Forum Commoner
Posts: 25
Joined: Sat Feb 25, 2006 3:22 am

Post by Stephen Bungert »

Volka, when I was doing test on my own php login system (before starting my thread here) I noticed that every time I refereshed the page I got a new Session ID, if this helps diagnose my problem. Can't get your code to work.

I never thought anything about the changing ID, it was the first time that I'd tried using sessions... I thought it must be supposed to change like that so I never mentioned it before.
Last edited by Stephen Bungert on Fri Oct 06, 2006 3:11 pm, edited 1 time in total.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

very strange, there are no syntax errors in the script. Please check again.


Does your browser reject all cookies?
Last edited by volka on Fri Oct 06, 2006 3:12 pm, edited 1 time in total.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Try this one:

Code: Select all

<?php session_start(); ?>
<html>
        <head><title>session test</head>
        <body>
                <p><?php echo 'time: ' . date('H:i:s'); ?></p>
                <p><?php echo 'id:' . session_id(); ?></p>
                <p><a href="<?php echo basename($_SERVER['SCRIPT_FILENAME']); ?>">reload</a></p>
        </body>
</html>
Stephen Bungert
Forum Commoner
Posts: 25
Joined: Sat Feb 25, 2006 3:22 am

Post by Stephen Bungert »

Volka, your test works now in Firefox but not IE - I only used IE before. Maybe it has something to do with IE?

In firefox the time stays the same and the id changes when I refresh the browser
Last edited by Stephen Bungert on Fri Oct 06, 2006 3:15 pm, edited 1 time in total.
Stephen Bungert
Forum Commoner
Posts: 25
Joined: Sat Feb 25, 2006 3:22 am

Post by Stephen Bungert »

everah, yours doesn't work in IE either, but in firefox it works like volkas. The time stays the same (except for the seconds) and the session ID changes.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

I forgot to close the title tag.

Code: Select all

<?php session_start(); ?>
<html>
        <head><title>session test</title></head>
        <body>
                <?php echo 'time: ', date('H:i:s'), ' | id:', session_id(); ?>
                <br />
                <a href="<?php echo $_SERVER['PHP_SELF']; ?>">reload</a>
        </body>
</html>
If the session_id changes every time then a new session is started every time, new session->no data.
Does your browser reject all cookies?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Browsers should have nothing to do with it, but it appears that your server is not setting the session id. I would guess there may be a problem with the session.save_path directive in your php.ini (or your permissions on that folder).
Stephen Bungert
Forum Commoner
Posts: 25
Joined: Sat Feb 25, 2006 3:22 am

Post by Stephen Bungert »

session.save_path = "C:/Dokumente und Einstellungen/Stephen/Lokale Einstellungen/Temp"

; Whether to use cookies.
session.use_cookies = 1

I found this in the php ini.

there are lots of files in "C:/Dokumente und Einstellungen/Stephen/Lokale Einstellungen/Temp" that start with 'sess' so I guess these must be to do with the php sessions. I've never seen files named like this before.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Does your browser reject all cookies?
Stephen Bungert
Forum Commoner
Posts: 25
Joined: Sat Feb 25, 2006 3:22 am

Post by Stephen Bungert »

No, I accept all cookies.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Code: Select all

<?php 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>
please reload this script several times and then post the last output here.
Stephen Bungert
Forum Commoner
Posts: 25
Joined: Sat Feb 25, 2006 3:22 am

Post by Stephen Bungert »

In IE I don't see anything, in Firefox I see:


time: 22:36:32

id:qtcgo0k49b7up5vu7kekit63o2

name:PHPSESSID

Array
(
)




reload
Post Reply