Skip navigation.

Part 3: PHP Equivalents for ASP Objects

Part 1 Language Basics
Part 2 Functions, Classes
Purpose ASP Object PHP Equivalent
Writing HTML
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:


For security, I would recommend disabling register_globals (set it to OFF). Then the variables are only available in the arrays:
$_POST, $_COOKIE and $_GET.

See examples below.

Redirecting to another location
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( ).

$avar = 99; 
/* 99 in $avar is overwritten now */
print $avar;
Form Variables





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:


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.

Response.Buffer = true
print "abc";
Script Timeout

Timeout is in seconds:


Timeout is in seconds:


Part 1 Language Basics
Part 2 Functions, Classes