Question:
php session problem occur in my script any one pls help me?
anonymous
2009-12-22 23:10:55 UTC
//sess1.php



<br /> Storing data in sessions <br />





Storing data in sessions



@session_start();
$_SESSION['temperature'] = "72";
?>

Stored the temperature as 72 degrees.


To read the temperature in a new page, click here.







// sess2.php


<br /> Retrieving data in sessions <br />





Retrieving data in sessions



session_start();

if(isset($_SESSION["temperature"])){
echo "Welcome. The temperature is " . $_SESSION['temperature'];
}
?>






In my serverside, the session is didn't retrieved. Why this error occur? The session is empty.
in my server, we have using php5. But this script run in local server.
//sess2.php
Three answers:
oracle
2009-12-24 02:57:37 UTC
Check your php.ini, you should have use session cookies turned on. This means session_start must be used before *any* output is sent to the browser (in your case the html tags).



Also, you are using the @ operator in front of session_start, this means to suppress any errors, if you remove that, php might tell you an error on why the sessions are not working.



HTH
anonymous
2009-12-24 11:02:41 UTC
Well , the reason of this is output is being generated before session_start();.

This is not the thing that we have to put it before tag , but we should not generate any output before session_start function.



So simple if you want to use it then always start your file with
// rest code after that.



I hope this will solve your problem
Atmey
2009-12-22 23:29:28 UTC
Headers like "session_start()" should be placed before I think.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...