Php session variables not saving


I am trying to use session variables in php but they don’t seem to be saved across page loads. Maybe I am misunderstanding something, if so please point it out. To test I created these two pages:


<?php session_start(); $_SESSION["key"]="value"; ?> key: <?=$_SESSION["key"]?>


key: <?=$_SESSION["key"]?>

The output of page1 is as expected, but when I click on the link to go to page2 I lose the session variable and the page just looks like "key: " Any assistance is appreciated, thanks.


OK I figured it out. I guess I need to add session_start() at the beginning of page2 as well and then I have access to the variable on page1. My mistake!


Also you should avoid using the short tag “<?” in your PHP scripts. Some default installations may not have them enabled, and they interfere with XML processing instructions.

Max discount on any plan with promocode SCJESSEYTOTAL


You’ve got a few problems with that code - you might want to look at this post, which has a very simple example of string and reading session information.


Oops! Never mind … didn’t see the responses before I replied … sorry about that!