In one file , I have <?php session_start(); // start up your PHP session! $_SESSION['plan'] = 'silver'; // store session data ?> In another file , which gets direct from above page , I have <?php session_start(); // start up your PHP session! echo "Plan0" . $_SESSION['plan']; $plan = $_SESSION['plan']; ?> But It doesn't DISPLAY the session value which is "plan".
Ok But Its same... Now, my 2nd File content is : <?php echo "Plan0" . $_SESSION['plan']; $plan = $_SESSION['plan']; ?>
I don't see anything wrong with it, other than the fact that $_SESSION['plan'] have blank value. session_start() must be called each time you run the PHP script if you wanna use sessions.
First I will suggest you to make sure the value has properly inserted in session. If yes probably when you jump from first to second page anywhere you are resetting session value.
try to add print_r($_SESSION); on each page, you can see the data of your session and if it is passed properly..
Try a simple test to make sure your sessions are working right. session_start(); $_SESSION['test'] = 'Session works'; echo $_SESSION['test']; PHP: If you get the text 'Session works' displayed on the screen you know your session are setup right. Glen
"PROPERLY" sense, make sure whatever have you inserted in session, has saved in it. you can var_dump($_SESSION['plan']) after inserting any value in it. if find any confusion query me again!!!
HuggyEssex , It works webshore88 , I tried echo and It works !! AliceWonder , cookie being sent ? Means ?
HTML is stateless. When you start a session, the session is stored according to a session ID. This session id is then referenced in a cookie sent to your browser. Next time your browser connects to web site, it sends the cookie as part of its connection headers so that the web site knows the connection is coming from the user associated with the session. If your browser is configured to reject cookies or reject cookies from the domain you are using, sessions won't work unless passes as GET variables (which is very insecure and should not be done). In your browser preferences, you should be able to see what the settings are with respect to cookies, and whether or not your browser is accepting them. Some over zealous virus protection software interferes with cookies because cookies can be used to track users.
Create these pages. index.php <?php session_start(); $_SESSION['test'] = 'The sessions are working fine.'; echo '<a href="view.php">Check session has been made</a>'; ?> PHP: view.php <?php session_start(); if(isset($_SESSION['test'])) { echo $_SESSION['test']; }else{ echo 'Sessions are not working.'; } ?> PHP: You need to go to index.php first, then after click the link which will take you to the second script. Just create these 2 files don't place any HTML around them, the most likely issue you have here is that you are sending something to the browser before the session is started. Just try what I said and let me know.
Index.php: Check session has been made view.php: The sessions are working fine. Here are My files : File1.php: this file calls file2.php File2.php:
Make this the new file2.php and let me know what it says. <?php session_start(); // start up your PHP session! if(session_id()){ echo "Session started!"; }else{ echo "Session not started!"; } $plan = $_SESSION['plan']; var_dump($plan); exit(0); $PlanPrevValue='0'; $PlanValue = '0' ; $PlanDuration='0'; If ($plan == 'silver') { $PlanPrevValue='89.00'; $PlanValue = '59.00' ; $PlanDuration =' 6 months '; session_destroy(); } ElseIf ($plan == 'gold') { $PlanPrevValue='199.00'; $PlanValue = '149.00' ; $PlanDuration =' 12 months '; session_destroy(); } ElseIf ($plan == 'diamond') { $PlanPrevValue='299.00'; $PlanValue = '249.00' ; $PlanDuration =' 24 months '; session_destroy(); } elseIf ($plan == 'platinum') { $PlanPrevValue='299.00'; $PlanValue = '349.00' ; $PlanDuration =' 36 months '; session_destroy(); } else { $PlanPrevValue='0'; $PlanValue = '0' ; $PlanDuration =' '; session_destroy(); } ?> PHP: