Emulating ASP's Application object with php
Posted: Mon Sep 02, 2002 1:28 pm
Hi, just wondering if anyone had tried to emulate the only thing i like about asp - the application object thing that lets you set a variable that can be accessed from all scripts?
I'm trying it myself using a little class that reads itself from a specific file at the beginning of the script and then serialises itself to the file on script termination, and was wondering if anyone else had tried anything similar they wanted to share?
For anyone interested, the basic usage is like this (more or less)
this example would just count how many times pages were requested - useless i know but meant as an illustration of how to use the class.
If anyone has tried something similar, I'd love to hear about it.
cheers, Sam
I'm trying it myself using a little class that reads itself from a specific file at the beginning of the script and then serialises itself to the file on script termination, and was wondering if anyone else had tried anything similar they wanted to share?
For anyone interested, the basic usage is like this (more or less)
Code: Select all
<?php
/* include the application class - not shown here because it is currently somewhere in between concept and code */
include("application.class.php");
$application = new application();
if( !isset($application->counter ) ){
$application->counter = 1;
}else{
$application->counter++;
}
echo "This server has served ".$application->counter." requests for scripts using application object";
?>If anyone has tried something similar, I'd love to hear about it.
cheers, Sam