Global.ASA in PHP




i am new to PHP :)
before i was using asp for server-side scripting :(
i wonder if there is a similar concept of global.asa in php :?

thanks a lot,
Maybe if you could tell us what global.asa does, we could help you.

I've heard ASP programmers confuse "global variables" and "session variables" before, so maybe that's what you're talking about. Check out the Sessions section of the manual.
in a nutshell here's what i understand of it:

whenever any client enters the site, or pages within the site,
the global.ASA file will be automatically called before anything else, to start the session.
it is also automatically called whenever the client exits the site.

my problem is this, i want to initialize some session variables for each user whenever they enter the site. but i don't know where do they enter the site so that i need something like a global.asa to do it because not every page in the site is php. i also want to know when will the user ends the session so that i can destroy the user's session variables.

thanks for any help,

katips :)


i was also trying to use $HTTP_SESSION_VARS but the PHP in my site is 4.0.6 and i found out searching from the web that it has some problems.
The Global.asa file is an optional file that can contain declarations of objects, variables, and methods that can be accessed by every page in an ASP application.
This are the only 4 events a Global.asa ca contain:
Application_OnStart, Session_OnEnd, Session_OnEnd and Application_OnEnd.

Well, in Php it´s a little bit different. You can put the code in a separated file or not. Ok, for session code is better at the very top of the page! And you don´t need that "Events"!

By default, in Php, a session ends everytime the user close the browser, so you don´t needto close/end it unless you want to use session.cookie_lifetime, same as Session.Timeout in ASP.

For login/logout system you can use session_write_close(); or session.destroy(); to end/finish a session. Equivalent to Session.Abandon in ASP.

You can you the next code to start your users session.
You can copy and save it as global.php if you want.
You can also include it in another file using include 'global.php'; , same as Server.Execute("file.asp") in ASP.
//  You can use this to give a name to your session

// To start a session

// Registering a sssion variable
You can/better use $_SESSION to get/set a session variable value.
// Setting a value
$_SESSION['User'] = 'Mary';

// Printing/showing value
echo $_SESSION['User']; // result: Mary
If you want to pass a session variable from one page to another one you have to call session_start(); at the very top of the page you wanna use it!

For more information about using session in Php, please see all related things in the link swirlee post!
thanks guys for the help... :)

anyway, i went to search for the solution over the web and there is no similar concept in php ( global.asa being an external "hidden" file that is automatically executed).

i just have to include the session module for every php that i use, like you suggested...