dead_elves Posted February 19, 2007 Share Posted February 19, 2007 I've tried adding variables to the $_SERVER variable, to no avail. It accepts an assignment just fine, but doesn't recognise the key on the following page. I know web servers are stateless, but there are mechanisms in other languages that perform this kind of function (the SERVER variable in ASP, for example, if I remember correctly) so I'm hoping I just missed something in the manual. test01.php: ----------- <?php $_SERVER["myobject"]="steve"; ?> test02.php: ----------- <?php echo $_SERVER["myobject"]; ?> Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted February 19, 2007 Share Posted February 19, 2007 Use sessions or cookies.... http://us2.php.net/manual/en/ref.session.php Quote Link to comment Share on other sites More sharing options...
dead_elves Posted February 19, 2007 Author Share Posted February 19, 2007 sessions/cookies won't work (I think...), since what I want to store should be persistent across all sessions. Basically I want to dynamically build a menu structure from a flat file and directory structure. I could do this on every page call, but that just seems like a huge waste. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 19, 2007 Share Posted February 19, 2007 Create a config file and include it on all pages, and define those variables or constants there. Edit: If you're saying this data will be changed by one user, and all users should then see the changes, use a database. Quote Link to comment Share on other sites More sharing options...
sspoke Posted February 20, 2007 Share Posted February 20, 2007 global array Quote Link to comment Share on other sites More sharing options...
dead_elves Posted February 20, 2007 Author Share Posted February 20, 2007 Create a config file and include it on all pages, and define those variables or constants there. includes would only cut down on the amount of typing and maintenance of the site - it would still have to be reprocessed on every call. global array Wouldn't that just affect the scoping on the page itself? Basically I want to build the content menu dynamically from a directory-and-file structure. This structure won't change often though, so it seems extremely ineffecient to me to rebuild it on every page call. I've toyed with the idea of storing the structure as an xml file and rereading that, but as I understand it, xml processing is almost as top-heavy as stepping through my directory structure would be. Quote Link to comment Share on other sites More sharing options...
dead_elves Posted February 20, 2007 Author Share Posted February 20, 2007 Edit: If you're saying this data will be changed by one user, and all users should then see the changes, use a database. At this point a database call does seem to be the best choice out of a bad bunch as far as efficiency goes, but I need to retain the directory structure because other applications will be accessing the data directly. Normally I would use servlets to build this type of site, but client constraints don't allow that this time, and I'm kinda stuck. Quote Link to comment Share on other sites More sharing options...
btherl Posted February 20, 2007 Share Posted February 20, 2007 Actually the config file is probably the fastest method. But the config file need not re-scan the structure every time it's called. The config file can be the product of the structure scanning, and can simple contain php variable definitions. Re-creation of the config file can be triggered any time the structure changes. The only way I can imagine that would improve on that is some kind of shared memory cache, which would avoid the overhead of parsing the php variable definition and constructing it each time. But I don't know of anything like that for php. Quote Link to comment Share on other sites More sharing options...
dead_elves Posted February 20, 2007 Author Share Posted February 20, 2007 The config file can be the product of the structure scanning, and can simple contain php variable definitions. That's not a bad idea. As I understand the PHP session tracking subsystem, session variables are stored in a similar manner. One would still have to come up with a mechanism to keep the data synchronised, but I suppose you could do that by adding a synchronisation counter of some sort that just polls the directory every now and again for changes. Obviously the ideal would be the ability to pass objects around from page to page, but within the limitations php, asp et al. have, this rocks. Thanks! Quote Link to comment Share on other sites More sharing options...
skali Posted February 20, 2007 Share Posted February 20, 2007 Create a global include file where you can create the object. Serialize the object and add it to users session. Now on in the same include file check if the object is not present then create the object otherwise just use it by unserliaze() the object. This way you will create this object once per session. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.