Jump to content

keeping data between scripts


SyncViews

Recommended Posts

Right now almost every page is making the same sql querys to get things like paths to the users template directory etc.

eg:

$result = $mysqli->query("SELECT style_path, style_name FROM styles WHERE style_id=$_SESSION[style]");

This seems a waste of resources and I'm certain it would be more efficent just to keep the whole lot in memory as an array...

$styles
        0 =>
                'name'        => 'Default'
                'path'        => 'styles/default'
        1 =>
                'name'        => 'Deep Space'
                'path'        => 'styles/deepspace'

So is there someway I can have this array present accross all my scripts? A shared global if you like.

Link to comment
https://forums.phpfreaks.com/topic/102750-keeping-data-between-scripts/
Share on other sites

Oh, by the way, thanks for making this topic, because it prompted me to rewrite my retrieve_user_info function on my little test application I wrote.  I meant to do it yesterday, but I procrastinated.  I had it so it queried the database EVERY single page to retrieve their info, but now I just store it in the session (and query) if it's not already set.

Web servers are stateless. The only way to share data between separate users is to store it in a database, a disk file, or a memory cache. Since, you already have it in a database, your choices would be to cache it in a disk file or a memory cache.

 

Sessions allow data for one visitor to be propagated between pages or between refreshes of a single page but sessions are not shared between separate users (and the session data is stored in files by default, so even if you could share session data between visitors, there is no advantage over caching the data in a disk file.)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.