Her er en kommentar - kald det bare en funktionsoversigt for PHP og ASP - fra et indlæg i en PHP Mailing Liste:
********** paste ************
ASP Application Object
has the methods
Lock
Unlock
Calling the lock method will lock all concurrent accesses to
application variables ("properties of the application object")
until unlock is called (or the page ends).
Usage example:
<%
Application.Lock
Application("visits") = Application("visits") +1
Application.Unlock
%>
<%= Application("visits") %> hits to this application.
PHPLIB has currently no $app object. Support for this is planned in the
next release of PHPLIB (PHPLIB-7).
ASP Request Object
has the slots
ClientCertificate
Cookies
Form
QueryString
ServerVariables
PHP gives access to Cookies as normal PHP variables and via
$HTTP_COOKIE_VARS. Form variables are accessible as normal PHP variables
and as $HTTP_GET_VARS and $HTTP_POST_VARS. The query string and other
server variables are available as normal PHP variables. See the output
of phpinfo() for full details. How do you access ClientCertificates with
PHP?
ASP Response Object
has the slots
Cookies
has the properties
Buffer
ContentType
Expires
ExpiresAbsolute
Status
has the methods
AddHeader
AppendToLog
BinaryWrite
Clear
End
Flush
Redirect
Write
PHP does not have a buffer property, because PHP always generates
unbuffered output. Consequently, there is no Clear method. If you want
buffered output, you have to buffer manually by appending to a string
using sprintf():
$buf .= sprintf("My Output<br>");
$buf .= sprintf("Goes here<br>");
and flush your buffer with
print $buf;
You clear your buffer by destroying $buf, as in
$buf = "";
In PHP, you cannot add headers and cookies to a response, because the
output is unbuffered. Instead, you create cookies with PHPs setcookie()
function and output headers using PHPs header() function. Calls to
either of them must go before ANY output on your page. This leads to a
specific programming style, the PHP normal form, which has all function
definition, result calculation and so on at the top of the page, without
any output at all. Depending on the result headers and cookies are
generated, then the result HTML is emitted. PHP has a flush() function,
but you rarely need it - PHP does not buffer.
Set the Content-Type using
header("Content-Type: image/gif");
or whatever you need. Set an expiration time $exp seconds in the future
using
$exp_gmt = gmdate("D, d M Y H:i:s", time()+$exp) . " GMT");
header("Expires: " . $exp_gmt);
or set $exp to an absolute timestamp and leave of the "time()+" in that
statement. Set the responde status using
header("Status: 401 Unauthorized");
You may also create a relocation (as in the Redirect method of ASP)
using
header("Location:
http://..../.../inded.html");
To create log messages with PHP, use the PHP syslog() function.
You don`t need BinaryWrite with PHP, because PHP is binary save. If you
open files with PHP using fopen() and you are not on a Unix system, see
the "wb" and "rb" open modes.
The equivalent to End is exit().
Write responses using "echo", "print" or "printf".
ASP Server object
has the properties
ScriptTimeout
has the methods
CreateObject
HTMLEncode
MapPath
URLEncode
In PHP, the script timeout and script memory usage can be controlled
from the php3.ini file. See max_execution_time and memory_limit in that
file.
rawurlencode(), rawurldecode(), urlencode(), urldecode(),
base64_encode(), base64_decode(), quoted_printable_decode(),
htmlspecialchars() and htmlentities() encode and decode for you just
like HTMLEncode and URLEncode (only better). There are additional
encoding and decoding function like addslashes(), quotemeta(),
stripslashes() and more.
CreateObject is an ASP method for communication with COM objects. If you
are on Unix, you don`t have this (but a multitude of PHP extensions). On
NT PHP, use Zeev`s COM-access from PHP.
PHP is independent from the webserver and does not have access to the
web servers path mapping, as MapPath does. But in mod_php you _could_
have such a function (anyone willing to write one?) and in CGI function
there is always PATH_INFO and PATH_TRANSLATED and several other useful
variables for the common cases (see phpinfo() output for details).
ASP Session object
has the properties
SessionID
Timeout
has the method
abandon
In PHPLIB, $sess->id is the session id, and $sess->lifetime is the
session lifetime in minutes. $sess->delete() destroys your current
session.
In ASP, you store values in your session object like
Session("memo") = "remember me"
In PHPLIB, you use any value and register it
$memo = "remember me";
$sess->register("memo");
PHPLIB requires that you frame your page with page_open() and
page_close() statements. Use the auto_init feature of PHPLIBs Session to
have Session_OnStart functionality.
PHPLIB also has user variables on authenticated pages. There is no
equivalent in ASP.
There are some predefined components that come with ASP:
MSWC.AdRotator
use any PHP ad rototor, there are many freely available.
MSWC.BrowserType
use the browsecap() function of PHP
ADO Database Access
PHP has many database access functions, including ODBC.
PHPLIB provides a nice abstraction that provides some
database independence.
MSWC.Nextlink
provides a list of URLs that can be browsed like a book.
Each URL in the list also has a descriptive text.
There are methods GetListCount (number of URLs in the list),
GetNextURL (return the next URL in the list depending on
the current page), GetPreviousURL, GetListIndex (return
the current index into the list), GetNthDescription,
GetNextDescription, GetPreviousDescription, GetNthUrl.
Easily done in PHP and pretty useless.
File system access in ASP is done via the VBScript FileSystemObject and
TextStream objects. In PHP, you use standard fopen(), opendir() and
stat(), like in C or other programming languages.
Feel free to add to this or to use this as part of a PHP-ASP migration
help.
Kristian
--
SH Online Dienst GmbH, Kristian Koehntopp,
Siemenswall, 24107 Kiel, +49 431 386 436 00
Using PHP3? See our web development library at
http://phplib.shonline.de/ (GPL)
********** paste slut ************
Med venlig hilsen
Chris Østergaard
ASP Udvikler
WebTime Internet
chris@webtime.dk