Part 2 Functions, Classes
| Purpose | ASP Object | PHP Equivalent |
| Writing HTML |
Response.Write(str) |
print $str; echo $str; print_r $debug_str; |
| Form, Cookie and QueryString variables. | Available in Request object. |
These variables are available automatically as global variables if you have configured the following in PHP.ini: variables_order="EGPCS" For security, I would recommend disabling register_globals (set it to OFF).
Then the variables are only available in the arrays: See examples below. |
| Redirecting to another location |
Response.Redirect(url) |
Header("Location: $url"); |
| Cookie Handling |
Response.Cookies(cookiename) = newval avar = Request.Cookies(cookiename) |
setcookie($cookiename, $newval); $avar = $_COOKIE[$cookiename]; |
| Application Variables | Application(appvarname) | Not available. Can be simulated with a database. |
| Session Variables |
Session(sessionname) = newval avar = Session(sessionname) |
In PHP4 or later, we mark certain variables as session variables using session_register($sessionname), and we call session_start( ) at the beginning of the .php page to restore the session variable values. Note that we pass the name of the variable, and not the variable itself into session_register( ). session_register('avar');
$avar = 99;
session_start();
/* 99 in $avar is overwritten now */
print $avar;
|
| Form Variables |
Request.Form("formvar") Request.QueryString("getvar") |
$_POST["formvar"]; $_GET["getvar"]; Alternately, GET and POST vars can be converted automatically to PHP variables. However this is a security risk if hackers are aware of the variable names used in your code. |
| Server Variables |
There are many server variables. See ASP documentation. An example: Request.ServerVariables("HTTP_HOST") |
For ISAPI modules, the server varibles are stored in the $_SERVER array. For CGI, they are stored as environment variables, available from the $_ENV array or getenv( ). An example: $_SERVER["HTTP_HOST"] using ISAPI module $_ENV["HTTP_HOST"] using CGI module See PHP, FastCGI and IIS for a more detailed discussion of high performance PHP on IIS. |
| Database Access | Microsoft's ADO technology is commonly used. |
ADO can be simulated using the ADOdb database library. This PHP library emulates ADO, and is designed by the author of this article. Limitations: only supports forward scrolling read-only cursors. |
| Buffering |
Response.Buffer = true
Response.Write("abc");
Response.Flush()
|
ob_start(); print "abc"; ob_end_flush(); |
| Script Timeout |
Timeout is in seconds: Server.ScriptTimeout(240) |
Timeout is in seconds: set_time_limit(240); |
Part 1 Language Basics
Part 2 Functions, Classes

