用php模拟asp.net是不大可能的,特别是对于php这样的对面向对象支持不完整的动态语言来讲,更是很大的困难.在这些说模拟是说可以由这个例子来理解asp.net的运行机制(又说深了,他仅仅是一个模以而以) .代码很简单,无需细说,本测试在win2000,iis5,php 4.4.0上运行通过
\n
page.php
\n
<?php
/*********************************************
*Sinoprise Function Classes
*CopyRight(c):2006 Sinoprise Technology Lab
*
*Unit Name: page.php
*func:
*Crate:Shuguang Yin 2006-07-15
*********************************************/
class SFC_Page
{
//环境变量
/*var Server;
var Session;
var QueryString;
var Post;
var Cookie;
var Files;
var Env;*/
//页面控制属性
var EnableViewState;
//页面属性
var CharSet;//页面字符集
var PageTitle;//页面的标题
var PageStyle;//页面的风格
function SFC_Page()
{
/*if (strcmp(substr(PHP_VERSION,0,1),4)>=0){
\n
Server = _SERVER;
Session = _SESSION;
QueryString = _GET;
Post = _POST;
Cookie = _COOKIE;
Files = _FILES;
Env = _ENV;
\n
}else{
\n
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;
\n
}*/
\n
this->EnableViewState = false;
\n
}
//发生在服务器状态还原之前
function PageInit()
{
}
\n
//发生在服务器状态还原之后,但在服务器端事件之前
function PageLoad()
{
}
\n
//发生在激发服务器端事件之后,但在生成任何东西之前
function PagePreRender()
{
}
\n
//发生在生成页面之时
function PageRender()
{
}
\n
//发生在网页生成完成之后
function PageUnLoad()
{
}
\n
//显示输出
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();
\n
}
//判断是第一次打开还是post
function IsPostBack()
{
}
//对ViewState进行编码
function EnCodeViewState()
{
echo “<input type=\\”hidden\\” name=\\”SFC_ViewState\\” id=\\”SFC_ViewState\\” “;
echo “Value=\\”".base64_encode(serialize(this)).”\\”";
echo “>”;
}
//对ViewState进行解码
function DeCodeViewState()
{
if (isset(_POST[\'SFC_ViewState\'])){
this = unserialize(base64_decode(_POST[\'SFC_ViewState\']));
}
}
}
?>
\n
页面文件,php.php
\n
<?
require_once(‘page.php’);
class PhpTest extends SFC_Page
{
var conut;
function PhpTest()
{
}
//发生在服务器状态还原之前
function PageInit()
{
}
//发生在服务器状态还原之后,但在服务器端事件之前
function PageLoad()
{
}
//发生在激发服务器端事件之后,但在生成任何东西之前
function PagePreRender()
{
}
//发生在生成页面之时
function PageRender()
{
echo ++this->conut;
//echo serialize(this);
echo “<br>”;
echo “<input type=submit value=\\”OOKK\\” name=hello>”;
}
//发生在网页生成完成之后
function PageUnLoad()
{
}
}
cls = new PhpTest();
cls->CharSet=”gb2312″;
cls->PageTitle=”页面的标题”;
cls->EnableViewState=true;
cls->Display();
?>
\n
来源:网络
\n