Page 1 of 1

Sessions

Posted: Fri Oct 24, 2003 12:25 pm
by OlezhkaPoi
I have got an array of data to store in session. But when the data is already in session, after next action it's dissapeared.

Have some of you some decisions, please tell me. :)

Posted: Fri Oct 24, 2003 12:54 pm
by Gen-ik
Make sure you have session_start(); at the top of every page that you will be using session variables on.

Posted: Fri Oct 24, 2003 2:52 pm
by jgoluch
Try this sample code to get a feel for how it works. I tried several other examples I found in the message posts and none of them worked. Remember that if you're not destroying sessions during development, it's probably a good idea to exit and restart your browser when changing session related code. Hope this helps

Code: Select all

<?php
session_start();
header("Cache-control: private");
?>

<html>
<head>
<title></title>
</head>
<body>

<?php
if($sessVar == 0)
&#123;
   session_register('sessVar');
   $sessVar = 1;
   $sArr = array(0,0,0,0);
   session_register('sArr');
&#125;
else
&#123;
   $sessVar++;
   for($i=0; $i<sizeof($sArr); $i++) &#123;
      $sArr&#1111;$i] += $i+1;
   &#125;
&#125;

for($i=0; $i<sizeof($sArr); $i++) &#123;
   echo "sArr&#1111;".$i."]= ".$sArr&#1111;$i].", ";
&#125;
echo ("<p><br>");
echo "sessVar = ".$sessVar."<p><br>";
?>
<a href="sesstest.php">Test</a>
</body>
</html>

Sessions

Posted: Sat Oct 25, 2003 6:07 am
by OlezhkaPoi
Thanks for advice, but it's still wiping the Arrays values. I think it must be something wrong with a php.ini. If you have some decisions, please write me!
:roll:

Posted: Sat Oct 25, 2003 7:00 am
by OlezhkaPoi
Who knows why does session works locality, and doesn't work remoteness?

Posted: Sat Oct 25, 2003 9:40 am
by volka
please try your script with

Code: Select all

<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
session_start();

[...remaining part of your script...]

session_write_close();
?>
if this doesn't work, what does

Code: Select all

<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);

session_start();
$sessionIdA = session_id();
@$_SESSION['counter'] += 1;
session_write_close();
// restart session
session_start();
$sessionIdB = session_id();
?>
<html>
	<head>
		<title>session test</title>
	</head>
	<body>
<?php
echo $sessionIdA,'<br />', $sessionIdB, '<br />';
echo 'session counter: ', @$_SESSION['counter'];
session_write_close();
?>
		<a href="<?php echo $_SERVER['PHP_SELF']; ?>">refresh</a>
	</body>
</html>
?

Sessions

Posted: Mon Oct 27, 2003 2:03 am
by OlezhkaPoi
Has worked! As soon as I have inserted the following code

error_reporting(E_ALL);
ini_set('display_errors', TRUE);

The prevention that the file in a directory/tmp cannot be read as directories do not exist has appeared, or the true way is specified not

Appeared, that I did not have in general such directory then I have created her.
I and thought, that a mistake trifling.

Thanks all for the offered decisions.
:D