用php模擬asp.net是不大可能的,特別是對于php這樣的對面向對象支持不完整的動態語言來講,更是很大的困難.在這些說模擬是說可以由這個例子來理解asp.net的運行機制(又說深了,他僅僅是一個模以而以) .代碼很簡單,無需細說,本測試在win2000,iis5,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
{
//環境變量
/*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){
$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;
}
//發生在服務器狀態還原之前
function pageinit()
{
}
//發生在服務器狀態還原之后,但在服務器端事件之前
function pageload()
{
}
//發生在激發服務器端事件之后,但在生成任何東西之前
function pageprerender()
{
}
//發生在生成頁面之時
function pagerender()
{
}
//發生在網頁生成完成之后
function pageunload()
{
}
//顯示輸出
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();
}
//判斷是第一次打開還是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']));
}
}
}
?>
頁面文件,php.php
<?
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();
?>
新聞熱點
疑難解答