Version: 1.0
Type: Class
Category: Other
License: GNU General Public License
Description: This is a simulation of many of the ASP objects, using PHP classes. Unfortunately, not every object nor property / method could be simulated. For the most part, many ASP properties could only be simulated as Methods. Below Are The Objects I could Simulate: Response Object Buffer(boolean) CacheControl(boolean) ContentType(string) Expires(date) Flush() IsClientConnected() Redirect(url) Write(string) Request Form QueryString ServerVariables Form (Instantiated Through Request Object) Count Index Item Key QueryString (Instantiated Through Request Object) Count Index Item Key Server CreateObject(class) HTMLEncode(string) MapPath(filename) ScriptTimeout(seconds) URLEncode(string) Session Value(variable name) SessionID[index] Contents[variable name] Index[index] Abandon() Please Note: The objects have to be invoked with PHP rules. Finally: Feel free to update this library, hence that I only created this library as a learning experience. This library helped me comfortably port from being an ASP developer to a PHP programmer.
<?php
/*
CONTACT ME AT michaelferrini@yahoo.com IF YOU WOULD LIKE TO ELABORATE ON THIS
COMPONENT */
Class Response
{
// Buffer Method
function Buffer($blnValue){
if($blnValue){
ob_start();
}
else{
ob_end_flush();
}
}
// CacheControl Method
function CacheControl($blnValue){
switch($blnValue){
case 0:
header ("Pragma: no-cache");
break;
case 1:
break;
}
}
// ContentType Method
function ContentType($strValue){
header("Content-Type: $strValue");
}
// Expires Method
function Expires($strValue){
if(checkdate($strValue)){
header ("Expires: $strValue");
}
else{
return 1;
}
}
// Flush Method
function flush(){
flush();
}
// IsClientConnected Method
function IsClientConnected(){
if(connection_aborted()){
return true;
}
else{
return false;
}
}
// Redirect Method
function Redirect($strURL){
header("Location: $strURL");
exit;
}
// Write Method
function Write($strExpression){
print $strExpression;
}
}
// Initialize Response Object
$Response = New Response;
Class Form
{
var $Count;
var $Index;
var $Item;
var $Key;
// Form Constructor
function Form(){
Global $HTTP_POST_VARS;
if(isset($HTTP_POST_VARS)){
# Set Item Property Associative Array
$this->Item = $HTTP_POST_VARS;
$FORM = $HTTP_POST_VARS;
$iCount = 0;
foreach($FORM As $F){
# Set Index Property Array
$this->Index[$iCount] = $F;
$iCount++;
}
# Set Keys Property Array
$this->Key = array_keys($FORM);
# Set Count Property
$this->Count = Count($FORM);
}
}
}
Class QueryString
{
var $Count;
var $Index;
var $Item;
var $Key;
// QueryString Constructor
function QueryString(){
Global $HTTP_GET_VARS;
if(isset($HTTP_GET_VARS)){
# Set Item Property Associative Array
$this->Item = $HTTP_GET_VARS;
$QS = $HTTP_GET_VARS;
$iCount = 0;
foreach($QS As $Q){
# Set Index Property Array
$this->Index[$iCount] = $Q;
$iCount++;
}
# Set Keys Property Array
$this->Key = array_keys($QS);
# Set Count Property
$this->Count = Count($QS);
}
}
}
class Request
{
var $Form;
var $QueryString;
var $ServerVariables;
// Request Constructor
function Request(){
Global $HTTP_SERVER_VARS;
$this->Form = new Form;
$this->QueryString = new QueryString;
$this->ServerVariables = $HTTP_SERVER_VARS;
}
}
// Initialize Request Object
$Request = new Request;
class Server
{
# CreateObject Method
function CreateObject($strClassString){
$oCOM = new COM($strClassString);
return $oCOM;
}
# HTMLEncode Method
function HTMLEncode($strHTMLExpression){
return htmlentities($strHTMLExpression);
}
# MapPath Method
function MapPath($strFileName){
return realpath($strFileName);
}
# ScriptTimeout Method
function ScriptTimeout($iSeconds){
return set_time_limit($iSeconds);
}
#URLEncode Method
function URLEncode($strURLExpression){
return urlencode($strURLExpression);
}
}
// Initialize Server Object
$Server = new Server;
class sessionVar
{
var $SessionID;
var $Contents;
var $Count;
var $Index;
// sessionVar Constructor
function sessionVar(){
session_start();
}
# Value Method
function Value($varName){
static $iCount;
if(isset($iCount) == false){
$iCount = 0;
}
$this->Contents[$varName] = session_register($varName);
$this->SessionID[$varName] = session_id($varName);
$this->Index[$iCount] = session_register($varName);
$iCount++;
$this->Count = $iCount;
}
# Abandon Method
function Abandon(){
session_unset();
}
}
$Session = new sessionVar;
?>