Hi,
I'm looking to find out if I can keep array contents "static" (i.e. retained) during successive loads of a page. The array would be created once and contents set depending on results of an SQL query. Various links on the page could be clicked and would cause the page to reload/refresh with some slightly different content (images). I can retain the few scalar variables I need by passing them with (appending to) the URL of the links mentioned above. Is it possible to pass an array this way also or is there another way to accomplish what I've described ?
Thanks,
John
Keeping array contents static during repeated page loads
Moderator: General Moderators
If you havent already check out the PHP.net site on the functions session_start() and session_register().
Heres a discussion on another forum about adding an array to a session variable:
http://forums.devshed.com/archive/5/2001/11/1/25129
Heres a discussion on another forum about adding an array to a session variable:
http://forums.devshed.com/archive/5/2001/11/1/25129
Alrighty then ! Either I'm missing something, I'm a complete idiot or both. I tried various session examples from various posts all to no avail. Here is a simple example to get started & build on using both scalar and array var's in a session...
Hope this helps someone. I feel much better now that I can actually see session var's maintained thru page refreshes !
Code: Select all
<?php
session_start();
header("Cache-control: private");
?>
<html>
<head>
<title></title>
</head>
<body>
<?php
if($sessVar == 0)
{
session_register('sessVar');
$sessVar = 1;
$sArr = array(0,0,0,0);
session_register('sArr');
}
else
{
$sessVar++;
for($i=0; $i<sizeof($sArr); $i++) {
$sArrї$i] += $i+1;
}
}
for($i=0; $i<sizeof($sArr); $i++) {
echo "sArrї".$i."]= ".$sArrї$i].", ";
}
echo ("<p><br>");
echo "sessVar = ".$sessVar."<p><br>";
?>
<a href="sesstest.php">Test</a>
</body>
</html>