Using PHP to simulate a asp.net page model

Source: Internet
Author: User

It's not possible to simulate asp.net with PHP, this is especially true for PHP, which is an incomplete dynamic language for object-oriented support. In these simulations it is said that this example can be used to understand the operating mechanism of ASP.net (again, he is just a modulo). The code is simple. , without elaborating, this test runs on 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
{

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;//title of page
var $PageStyle;//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 a server-state restore
function Pageinit ()
{
}

Occurs after a server-state restore, but before the server-side event
function Pageload ()
{
}

Occurs after a server-side event is fired, but before anything is generated
function Pageprerender ()
{
}

Occurs when the page is generated
function Pagerender ()
{
}

Occurs after the Web page generation completes
function Pageunload ()
{
}

Display output
function Display ()
{
$this->pageinit ();
if ($this->enableviewstate) {
$this->decodeviewstate ();
}
$this->pageload ();
$this->pageprerender ();
echo "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 ();

}

Is it the first time to open or post a judge?
function IsPostBack ()
{

}
To encode a ViewState
function Encodeviewstate ()
{
echo "<input type=\" hidden\ "name=\" sfc_viewstate\ "id=\" "sfc_viewstate\";
echo "Value=\" ". Base64_encode (Serialize ($this))." \"";
echo ">";
}
Decoding the ViewState
function Decodeviewstate ()
{
if (Isset ($_post[' sfc_viewstate ')) {
$this = Unserialize (Base64_decode ($_post[' sfc_viewstate '));
}
}
}
?>

Paging file, php.php

?
Require_once (' page.php ');

Class Phptest extends Sfc_page
{
var $conut;

function Phptest ()
{

}
Occurs before a server-state restore
function Pageinit ()
{
}

Occurs after a server-state restore, but before the server-side event
function Pageload ()
{
}

Occurs after a server-side event is fired, but before anything is generated
function Pageprerender ()
{
}

Occurs when the page is generated
function Pagerender ()
{
echo + + $this->conut;
Echo Serialize ($this);
echo "<br>";
echo "<input type=submit value=\" ookk\ "name=hello>";
}

Occurs after the Web page generation completes
function Pageunload ()
{
}
}

$cls = new Phptest ();
$cls->charset= "gb2312";
$cls->pagetitle= "title of the page";
$cls->enableviewstate=true;
$cls->display ();
?>



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.