Re: Persistant variables in PHP?

From: Date: Tue, 05 Sep 2000 22:08:21 +0000
Subject: Re: Persistant variables in PHP?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-15395@lists.php.net to get a copy of this message
> Is there any built-in method of making variables persistant > across all sessions and users? ie like session variables except > global to all users? This isn't overly hard to add myself but > I'd like to have it handled automaticlly the way sessions are. > > For a stupid example I could: > > --- > persistant ( "hit_counter" ); > session_register ( "user_hits" ); > > $hit_counter++; > $user_hits++; > > print "This page has been viewed $hit_counter times, $user_hits by you."; > --- A hit counter is probably a bad idea as the atomicity of it is going to be important. A bit counter is best implemented by having an auto-incrementing field in an SQL server and just incrementing the counter with an insert query. But in general server-wide variables are pretty simple to implement. include 'globals.inc'; Then in globals.inc pull set the value of the globals, perhaps pulling them from a database backend. Then define a request_shutdown function that saves the current values of the relevant variables. You could even auto_prepend globals.inc which would effectively make it completely transparent. All the script writer sees are these global variables that she can manipulate and the changed values are seen by all other scripts. -Rasmus

« previous php.general (#15395) next »