This discussion is confined to all versions of Internet Information Server hosting Active Server Pages (ASPs) up to version 5 (just before ASP.NET) and PHP 4.1.0 (specifically referring to the new autoglobals). Flippantly speaking, of course, ASP is all about creating objects to access their respective properties and methods while PHP is largely about calling functions—many, many functions—or accessing a predefined variable.
The table below summarizes common ASP object methods/properties and the equivalent PHP function or predefined variable:
| ASP Method/Property | PHP Function Or Predefined Variable |
|---|---|
Request.Cookies.Item(vKeyName) | $_COOKIE[$keyName]; |
Request.Form.Item(vKeyName) | $_POST[$keyName]; |
Request.QueryString.Item(vKeyName) | $_GET[$keyName]; |
Request.ServerVariables.Item("SERVER_NAME") | $_SERVER['SERVER_NAME']; |
Response.Cookies.Item(vKeyName) = vCookieValue | setcookie($keyName, $cookieValue); |
Response.Redirect(vURI) |
where header("Location:
http://" . $_SERVER['HTTP_HOST']
. dirname($_SERVER['PHP_SELF'])
. "/" . $relative_url);
|
Response.Write(vURI) |
The absence of parenthesis for
The other PHP functions listed here for the sake of completion are far more powerful and complex than what we expect from ASP. |
VBScript example: Set objCNN = Server.CreatObject("ADODB.Connection")
Response.Write(objCNN.Version)
|
This function is not documented as being in all versions of PHP but part of the Concurrent Versions System. The assumption here is that this function may be in the win32 build of PHP but not others. |
Server.HTMLEncode(vStr) |
A more powerful (and “typographically correct”) function is |
Server.MapPath(vStr) | realpath($str); |
Server.ScriptTimeout(60) | set_time_limit(60); |
Server.URLEncode(vURI) |
Conversely, the These functions encodes according to the PHP supports the RFC1738 standard through the |
PHP has over a half-dozen “ob” functions, referring to the output buffer. This increased functionality allows PHP to distinguish between destroying the output buffer and simply erasing it (among other things). However, the following table centers upon direct translation:
| ASP | PHP |
|---|---|
Response.Buffer = True | ob_start(); |
Response.Flush | ob_end_flush(); |
Unlike the ASP directive, the PHP functions governing server-side includes allows both absolute and relative paths to included files. There are four PHP functions used to include files: include(), include_once(), require() and require_once(). These functions depend on the configuration directive include_path being set to resolve relative paths (so we can see a directive behind these functions).
| ASP | PHP |
|---|---|
<!--#include file="./foo.asp"--> |
The |
<!--#include virtual="./inc/foo.asp"--> |
Note that the relative path here does not have leading dots or slashes. This is because of the dependency on the The
This example uses Windows paths. |
| ASP | PHP |
|---|---|
<%@ ENABLESESSIONSSTATE=True %> | session_start(); |
Session.Abandon | session_destroy(); |
Session.Contents.Item(vKeyName) | $_SESSION[$keyName]; |
Session.Contents.Remove(vKeyName) | unset($_SESSION[$keyName]); |
Session.Contents.RemoveAll |
Or
|
PHP 4.x allows setting the level of error reporting, raising errors and specifying an error handling function. There is even an error control operator @. These features do not directly relate to ASP—especially VBScript ASP. The try…catch…finally statement of JScript and the Error Resume Next statement of VBScript both suggest the existence of an exception object or an error object, respectively. These ASP error objects hold error numbers and descriptions. There are no such things in PHP.