It is impossible to simulate ASP.NET with PHP, especially for a dynamic language like PHP that has incomplete object-oriented support. It is even more difficult. When I say simulation in these words, I mean that ASP can be understood through this example. The operating mechanism of .net (again, it is just a model). The code is very simple, no need to elaborate. This test is run on win2000, iis5, php 4.4.0 through
page.php
<?php
/****************************************************** ******************************
*Sinoprise Function Classes
*CopyRight(c):2006 Sinoprise Technology Lab
*
*Unit Name: page.php
*func:
*Crate:Shuguang Yin 2006-07-15
*************************************************** *******************************/
class SFC_Page
{
//environment variables
/*var $Server;
var $Session;
var $QueryString;
var $Post;
var $Cookie;
var $Files;
var $Env;*/
//Page control properties
var $EnableViewState;
//Page properties
var $CharSet;//Page character set
var $PageTitle; //The title of the page
var $PageStyle;//The style of the page
function SFC_Page()
{
/*if (strcmp(substr(PHP_VERSION,0,1),4)>=0){
$Server = $_SERVER;
$Session = $_SESSION;
$QueryString = $_GET;
$Post = $_POST;
$Cookie = $_COOKIE;
$Files = $_FILES;
$Env = $_ENV;
}else{
global $HTTP_SERVER_VARS,$HTTP_GET_VARS,$HTTP_POST_VARS,$HTTP_COOKIE_VARS,$HTTP_POST_FILES;
global $HTTP_ENV_VARS,$HTTP_SESSION_VARS;
$Server = $HTTP_SERVER_VARS;
$Session = $HTTP_SESSION_VARS;
$QueryString = $HTTP_GET_VARS;
$Post = $HTTP_POST_VARS;
$Cookie = $HTTP_COOKIE_VARS;
$Files = $HTTP_POST_FILES;
$Env = $HTTP_ENV_VARS;
}*/
$this->EnableViewState = false;
}
//Occurs before server state is restored
functionPageInit()
{
}
//Occurs after server state is restored, but before server-side events
function PageLoad()
{
}
//Occurs after the server-side event is fired, but before anything is generated
function PagePreRender()
{
}
//Occurs when the page is generated
functionPageRender()
{
}
//Occurs after the web page is generated
function PageUnLoad()
{
}
//display output
function Display()
{
$this->PageInit();
if ($this->EnableViewState){
$this->DeCodeViewState();
}
$this->PageLoad();
$this->PagePreRender();
echo "<html><title>".$this->PageTitle."</title>";
echo "<META http-equiv=Content-Type content="text/html; charset=".$this->CharSet."">";
echo "<body ".$this->PageStyle.">";
echo "<form name="SFC_WebForm" id="SFC_WebForm" method="post" action="".$_SERVER['PHP_SELF']."">";
$this->PageRender();
if ($this->EnableViewState){
$this->EnCodeViewState();
}
echo "</form></body></html>";
$this->PageUnLoad();
}
//Determine whether it is the first time to open or post
function IsPostBack()
{
}
//Encode ViewState
function EnCodeViewState()
{
echo "<input type="hidden" name="SFC_ViewState" id="SFC_ViewState" ";
echo "Value="".base64_encode(serialize($this)).""";
echo ">";
}
//Decode ViewState
function DeCodeViewState()
{
if (isset($_POST['SFC_ViewState'])){
$this = unserialize(base64_decode($_POST['SFC_ViewState']));
}
}
}
?>
Page file,php.php
<?
require_once('page.php');
class PhpTest extends SFC_Page
{
var $conut;
functionPhpTest()
{
}
//Occurs before server state is restored
functionPageInit()
{
}
//Occurs after server state is restored, but before server-side events
function PageLoad()
{
}
//Occurs after the server-side event is fired, but before anything is generated
function PagePreRender()
{
}
//Occurs when the page is generated
functionPageRender()
{
echo ++$this->conut;
//echo serialize($this);
echo "<br>";
echo "<input type=submit value="OOKK" name=hello>";
}
//Occurs after the web page is generated
function PageUnLoad()
{
}
}
$cls = new PhpTest();
$cls->CharSet="gb2312";
$cls->PageTitle="Title of the page";
$cls->EnableViewState=true;
$cls->Display();
?>
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=932084