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.
Code:
<?php
// You can use this to give a name to your session
init_set('session.name','SID');
// To start a session
session_start();
// Registering a sssion variable
session_register('User');
?>
You can/better use
$_SESSION to get/set a session variable value.
Example:
Code:
<?php
// 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!