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
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.

Link to comment
Share on other sites

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.)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.