Forum Moderators: coopster

Message Too Old, No Replies

ASP Global.asa equivalent in PHP?

Want to run code once per visitor and set a global var. on session start

         

fitzer

4:38 pm on Jan 15, 2007 (gmt 0)

10+ Year Member



I'm new to PHP but have plenty of experience with ASP. ASP's Global.asa allows you to execute code once on a per visitor (per session) basis using the "Session_OnStart" subroutine:

Session_OnStart - This event occurs EVERY time a NEW user requests his or her first page in the ASP application.

Is there an equivalent feature to the Global.asa in PHP? I'm working on a site that is hosted on a UNIX server, running PHP. I'd like to do a DB lookup to check the visitor's IP address and set a global session variable for that user (but only do it once versus doing the lookup on each page).

Any feedback would be much appreciated.

eelixduppy

4:42 pm on Jan 15, 2007 (gmt 0)



If I understand you correctly you can make something simliar:

if(!isset($_SESSION['session_var'])) {
Start_Session();
}

Then you'd be able to put whatever you wanted in the Start_Session function that you want to execute the first time the session is initiated.

Here's some more info on sessions [us2.php.net].

Good luck :)