Click to See Complete Forum and Search --> : Question about resources!
katten
09-16-2008, 07:41 AM
So i was messing around last night trying to find a good way to store user information between pages instead of just saving the id in a session then querying the database on each page view!
So my idea was to use memcache, mysql or default session handling to store a serialized version in sessions :eek:
Is this a better idea or should i stick to querying the database on each load?
NogDog
09-16-2008, 09:19 AM
Hard to say without more info. Certainly sessions are designed to store data between multiple requests, so that would be my first inclination. As to serializing anything, generally speaking that should not be needed for normal session usage (e.g., objects are automatically serialized when saved to $_SESSION).
katten
09-16-2008, 09:42 AM
if im not wrong they only work correctly when passed to $_SESSION if the class implements __sleep()
NogDog
09-16-2008, 11:53 AM
if im not wrong they only work correctly when passed to $_SESSION if the class implements __sleep()
This works OK for me (running PHP 5.2.6):
<?php
session_start();
class Test
{
public $var = '';
}
if(isset($_GET['x']))
{
$test = $_SESSION['test'];
echo "<pre>".print_r($test,1)."</pre>";
}
else
{
$test = new Test();
$test->var = 'fubar';
$_SESSION['test'] = $test;
}
?>
<p><a href="?x=1">Click me.</a></p>