Page 1 of 1

session variables

Posted: Thu Aug 18, 2005 8:13 pm
by nmullane
I'm trying to extract a variable from a string within a session record in a MYSQL database. During a session this is obviously no problem as I can call "$_SESSION['value']['user_id']", however, I am writing a garbage collection routine that will remove records in other tables based on this user id which is in the value array of the session record.

What I need is a parse routine that I can call within the gc function to give me this value ... PHP obviously does this to give me the value in the example above, but I don't think I have access to this from the gc function. The string looks something like this:

value|a:2:{s:7:"user_id";s:2:"5";s:9:"user_type";s:1:"3";}

Any help would be appreciated - or is there an easier way to go about this?

Thanks

Nog.

Posted: Thu Aug 18, 2005 8:55 pm
by raghavan20
I dont know whether I understood you...anyway let me give a go

Code: Select all

foreach($_SESSION["value"] as $key){
	echo $key."<br />";
}

Posted: Thu Aug 18, 2005 8:57 pm
by feyd
could have swore I posted to this earlier, but I guess not.. Anyways, here's a database session handling system I posted a while ago:

viewtopic.php?t=23781

You should be able to adapt the functions/methods to recreate the session array so you can do whatever calculations you need to against it. :)


For future references, this link can be found in the Useful Posts thread.