Sessions question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jgoluch
Forum Newbie
Posts: 5
Joined: Tue Oct 21, 2003 9:38 am

Sessions question

Post by jgoluch »

Hi,

I'm trying to find a way to keep array contents static (i.e. retained) thru multiple page loads/refreshes. From what I can tell, sessions might be the way to go. The examples I've seen so far show sessions as a way to transfer array contents across different pages. My question: Can sessions be used to retain array contents (i.e. not have the array re-initialize) upon a single page reload/refresh ? Any examples of such...?

Thanks,

John
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

Code: Select all

<?PHP session_start();
$_SESSION['var'] = $pagevar; ?>
<html>
<body>
<?PHP echo "$pagevar"; ?>
</body>
</html>
not sure if you can use arrays in sessions, but if you can, it'd be like this:

Code: Select all

<?php
for(int i=0;i<num;i++)
{
$_SESSION['something[i]'] = $something[i];
}
?>
(num = number of things in the array)
that would save all the array variables to session variables
Post Reply