It is unlikely to use PHP to simulate Asp.net. Especially for dynamic languages such as PHP that do not have full object-oriented support, it is very difficult. in these cases, the simulation can be used to understand the operating mechanism of Asp.net. (Furthermore, it is just a model ). the code is very simple. You do not need to elaborate on it. This test passes through Win2000, iis5, and PHP 4.4.0.
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 variable
/* Var $ server;
VaR $ session;
VaR $ querystring;
VaR $ post;
VaR $ cookie;
VaR $ files;
VaR $ ENV ;*/
// Page control attributes
VaR $ enableviewstate;
// Page properties
VaR $ charset; // page Character Set
VaR $ pagetitle; // The page title
VaR $ pagestyle; // Page Style
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 the server status is restored
Function pageinit ()
{
}
// Occurs after the server state is restored, but before the server event
Function pageload ()
{
}
// Occurs after a server event is triggered, but before anything is generated
Function pageprerender ()
{
}
// When the page is generated
Function pagerender ()
{
}
// After the webpage is generated
Function pageunload ()
{
}
// Display the 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> $ 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 "> ";
}
// Decodes 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;
Function phptest ()
{
}
// Occurs before the server status is restored
Function pageinit ()
{
}
// Occurs after the server state is restored, but before the server event
Function pageload ()
{
}
// Occurs after a server event is triggered, but before anything is generated
Function pageprerender ()
{
}
// When the page is generated
Function pagerender ()
{
Echo ++ $ this-> conut;
// Echo serialize ($ this );
Echo "<br> ";
Echo "<input type = submit value =/" ookk/"name = Hello> ";
}
// After the webpage is generated
Function pageunload ()
{
}
}
$ CLS = new phptest ();
$ CLS-> charset = "gb2312 ";
$ CLS-> pagetitle = "page title ";
$ CLS-> enableviewstate = true;
$ CLS-> display ();
?>