Sessions - Am I missing something

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

Post Reply
User avatar
mendingo
Forum Commoner
Posts: 28
Joined: Sun May 23, 2004 1:27 pm

Sessions - Am I missing something

Post by mendingo »

As I understand it, once a session variable is set, it is set as long as the browser is left open, right?

So with this code:

Code: Select all

session_start;
print($_SESSION&#1111;'test']."<br>");
if(!isset($_SESSION&#1111;'test']))
&#123;
	$_SESSION&#1111;'test'] = "hello";
&#125;	
print($_SESSION&#1111;'test']."<br>");
When the page is first loaded, it displays en empty line, then "hello", as it should.

However, when I referesh the page, surely it should print "hello" twice? Why doesn't it? Is this a php bug? Am I missing something?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

session_start is a function, therefor it should be called as:

Code: Select all

session_start();
//........ rest of the code
Note the parethesis.
User avatar
mendingo
Forum Commoner
Posts: 28
Joined: Sun May 23, 2004 1:27 pm

Post by mendingo »

Sorry, yeah, the perentheses are there in the real code... just missed them out when typing it here.
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

It works as expected on my server..

http://lps.no-ip.org/try.php

Try copying the exact code you pasted here, and adding the parenthesis..
User avatar
mendingo
Forum Commoner
Posts: 28
Joined: Sun May 23, 2004 1:27 pm

Post by mendingo »

just did, and I still get the same problem.

http://fourleggedostrich.no-ip.com/external/test.php

Perhaps it's a bug in PHP 4.3.0 (which I have installed)... after I've moved around the site where this initially occured a while, it starts working again.

What PHP version do you have?
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

HMMM

I see only one 'hello' for both links given?
User avatar
mendingo
Forum Commoner
Posts: 28
Joined: Sun May 23, 2004 1:27 pm

Post by mendingo »

You will... you then need to refresh the page. That's when 2 should appear, because "hello" is already stored in the session
Post Reply