Session variables

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
mikeb
Forum Commoner
Posts: 60
Joined: Tue Jul 08, 2003 4:37 pm
Location: Dublin, Ireland

Session variables

Post by mikeb »

Hi,

I'm trying to get session variables working. I have a local (development) version of my site on win2k/apache/php4x/mysql. The remote site uses Linux/apache/php4x/mysql. Ok, I am going through a tutorial from Devshed which supplies this code (which I'm using to test my setup):

<?
session_start();
session_register("SESSION");

if (! isset($SESSION)) {
$SESSION["count"] = 0;
echo "<li>Counter initialized, please reload this page to see it increment";
} else {
echo "<li>Waking up session $PHPSESSID";
$SESSION["count"]++;
}
echo "<li>The counter is now $SESSION[count] ";
?>

Simple enough piece of code! It adds one to the variable on refreshing the page and displays the new value each time. Works fine remotely, but not locally. No error message locally either. Keeps printing the value of $SESSION[count] as zero. Don't get the 'waking up session...' echoing either. I did a side by side comparison with phpinfo() on both servers. Both match in all the [session] settings. Any idea what could be wrong locally?
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

- Put your code in

Code: Select all

 tags for easier reading
- try this:
[syntax=php]<? 
session_start(); 

if (! isset($_SESSION)) { 
$_SESSION['count'] = 0; 
echo "<li>Counter initialized, please reload this page to see it increment";
} 
else { 
echo "<li>Waking up session $PHPSESSID"; 
$_SESSION['count']++; 
} 
echo "<li>The counter is now $_SESSION['count'] "; 
?>[/syntax]
Last edited by d3ad1ysp0rk on Wed Feb 25, 2004 3:54 pm, edited 1 time in total.
mikeb
Forum Commoner
Posts: 60
Joined: Tue Jul 08, 2003 4:37 pm
Location: Dublin, Ireland

Post by mikeb »

Thank you! I'll give that a try. I'm presuming a dollar underscore for the third line of php?

thanks,

Mike
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

yup, sorry i forgot that one :P

*edited*
Post Reply