LDP/LDP/howto/linuxdoc/PHP-HOWTO.sgml

3050 lines
118 KiB
Plaintext
Raw Blame History

<!doctype linuxdoc system>
<!--
************************** begin comment *****************************
The following is the HOW-TO for programming in PHP.
This document is in the SGML format. You must use sgml package to
process this document
************************* end of comment *****************************
-->
<!--
************************** SGML USER GUIDE *****************************
The SGML user guide on linux is located at /usr/doc/sgml-tools
Read the example.sgml and guide.html documents.
Usage:
HTML sgml2html foo (Do not give extension .sgml here!!)
Text sgml2txt foo.sgml
Latex sgml2latex foo.sgml
Note: Use 2 dashes - before language, error while compiling
Postscript sgml2latex -language=english -o ps foo.sgml
DVI sgml2latex -d foo.sgml
Lyx sgml2lyx foo.sgml
Richtext sgml2rtf foo.sgml
gnuinfo sgml2info foo.sgml
man sgml2txt -man foo.sgml
SGML sgmlcheck foo.sgml
************************* end of comment *****************************
-->
<article>
<!-- Title information -->
<title>PHP HOW-TO
<!-- chapt change
PHP HOW-TO
-->
<author>Al Dev (Alavoor Vasudevan)
<htmlurl url="mailto:
alavoor[AT]yahoo.com
" name="
alavoor[AT]yahoo.com
">
<date>v27.6, 05 Oct 2002
<abstract>
This document tells you howto develop PHP programs and also to migrate all the
Windows 95 GUI applications to powerful PHP + HTML + DHTML + XML + Java applets + Javascript.
The information in this document applies to all the operating sytems
where PHP is ported that is - Linux, Windows 95/98/NT/ME/2000/XP, BeOS,
Apple Macintosh (is the son of FreeBSD Unix??),
OS/2, all flavors of Unix like Solaris, HPUX, AIX, SCO, Unixware, Sinix, BSD, SunOS, etc..
and mainframe operating systems and on all operating systems where "C" compiler is available.
</abstract>
<!-- Table of contents -->
<toc>
<!-- Begin the document -->
<sect>Introduction
<p>
<bf>
(The latest version of this document is
at <url url="http://www.milkywaygalaxy.freeservers.com">. You may
want to check there for changes).
</bf>
<it><bf>Definition:</bf> PHP is a simple, object-oriented,
interpreted, robust, secure, very high-performance, architecture neutral, portable,
dynamic scripting language. PHP has "class" keyword similar to Java's "class" keyword.
And PHP is designed such that it is 5 times faster than Java, since there is no virtual machine.
PHP is very fast becoming a standard, general purpose, object oriented scripting language.
PHP is not only meant for web applications but also can be used
for developing general applications.
</it>
<bf>
PHP is the next big thing after HTML because today nobody writes static HTML but
uses PHP (generate on the fly, embedded dynamic HTML). PHP 'kind-of' supercedes "static HTML".
PHP is a very powerful scripting language.
PHP will overtake PERL/Python and will replace PERL/Python.
PHP is the next-generation PERL/Python scripting.
PHP can do whatever PERL or Python does and actually does much more, much better and
much, much cleaner.
</bf>
PHP stands for 'Hypertext Pre-Processor' and is a server
side HTML scripting/programming language.
PHP is C-like Web scripting language runs on Apache, Netscape/iPlanet, and Microsoft IIS Web
servers.
PHP is a tool that lets you create dynamic web pages. PHP-enabled web pages
are treated just like regular HTML pages and you can create and edit them
the same way you normally create regular HTML pages.
PHP lets you write simple scripts right in your HTML files much like
JavaScript does, except, unlike JavaScript PHP is not
browser-dependant. JavaScript is a client-side html-embedded
language while PHP is a server-side language.
PHP is similar in concept to Netscape's LiveWire Pro product and Microsoft's ASP and
Sun Microsystem's JSP.
PHP is not only used for creating web applications, but also for creating general standalone
applications.
PHP's strength are :
<itemize>
<item> PHP is the most superior technology. Other technologies PERL, Python,
Tcl, VB script, ASP are older and inferior technologies. Even Java/JSP is inferior to PHP.
<item> Open source
<item> Easily learned syntax
<item> Broad database connectivity
<item> Massive library of contributed extensions
<item> General purpose scripting language much superior to PERL, VB script, ASP, JSP.
</itemize>
<bf>Why PHP ?</bf>
PHP is the best because of the following reasons:
<itemize>
<item> PERL is the "ancestor" of PHP and PERL is used for a very long
time (more than 25 years old?).
PHP has an advantage over PERL - PHP supports client-side code and is easier to
compile into a executable. User base of PERL is very large.
PHP tries to imitate PERL and complement the PERL technology.
PERL programmers like PHP!
PHP is actually a "modern PERL", but with a different name called "PHP".
<item> Java is object-oriented but is very SLOW. Java programs run very slow.
Also Java is immensely complex
and sophosticated technology (has many layers like JVM, JIT compiler and others). And
complexity and sophostication leads to problems. If there is Linux on server-side
then why do you need Java in servers ? And Java is more like a system programming
language and it is faster to develop in scripting languages (like PHP).
<item> Python is "good" but there are no C like brackets/braces which are useful for
code navigation in vi editor. It is like your hand is broken if you cannot navigate rapidly
the source code using vi/emacs editor's seek braces/brackets commands. PHP is technologically
more advanced than Python.
<item> PHP is the best because it is object oriented and has the best
features of C/C++/Java/PERL/Python.
It can replace PERL, Python, Java, C, C++, awk, Unix shell scripting, MS Visual Basic and others!!
PHP runs direct and PHP is written in C.
<item> Each and every computer programmer knows why PHP is the best.
Ask your nearby computer programmer.
<item> Only PHP will prevail in the 21st and 22nd century and beyond!
<item> Why do think every PERL, Python and Java programmers are flocking to PHP ?? There is
a very strong reason.
<item> Every person in the world wants PHP. PHP blast is causing shock-waves around the world!!
<item> The world is dominated by PHP. There is PHP everywhere and anywhere... PHP, PHP, PHP everywhere..
</itemize>
PHP was kept the <bf>"top secret and strictly confidential"</bf>
computer language by many companies in the world, but now had become
the most well-known and most widely used object oriented scripting language for
web, internet, e-commerce, general purpose and business-to-business projects.
Even today many competing companies keep PHP language as a
highly confidential matter not disclosing to outsiders (competitors).
PHP will storm the entire world and will take the IT industry by surprise!!
The power of PHP is that it is <bf>cross-platform and runs everywhere!!</bf>
It runs on Linux, Windows 95/98/NT/2000/XP, Solaris, HPUX and all
flavors of UNIX. PHP is write once and deploy anywhere and everywhere.
It runs on many web-servers like Apache, Microsoft IIS, etc..
PHP runs 5 to 20 times faster than Java!! In actual benchmarks, PHP was about
3.7 times faster than JSP (see <ref id="benchmarks">). PHP is extremely easy to use
and you can develop very complex web/e-commerce/general-standalone applications
very rapidly in a very short period of time.
Developing applications in PHP is about TWO times faster than developing in programming
language like Java (because there is no need for compilation in PHP).
(In future PHP language will imitate most features of Java language and
Java programmers will <bf>love</bf> PHP. And PHP will have java keywords
like class, extends, interface, implements, public, protected, private etc..).
It has object oriented features and takes the best features from Java,
C++, PERL and "C" languages. PHP language is a <it>marriage</it> of
best features from Java, C++, PERL, Python and C.
PHP is the <bf>real gem</bf> of all the scripting/programming languges
and will soon become the "MECCA" for programmers world-wide!!
PHP has a huge user base and a large
developer base as it runs on both Window95/NT/2000/XP and all flavors of UNIX'es.
A big surprise is waiting for us - <bf>Most probably PHP will be the
scripting language of the 21st century!!</bf>
PHP can be compiled and optimized to make it run even faster by using the
Zend Optimizer. Zend optimizer is integrated with PHP in PHP version 4.0.
First, you will write your application in PHP scripting language
during development, testing and debugging. Once the project is ready for
deployment you will use the Zend compiler to
compile the PHP to create executable which will run very fast.
You would normally use a combination of
PHP (70% code) + HTML/DHTML/XML (25% code) + Javascript (5% code client side validations)
for your e-commerce projects.
<sect> PHP runs on Microsoft Windows!!<label id = "mswin">
<p>
PHP initially started on UNIX platform, but it is very portable and
runs on MS Windows and MS IIS webserver.
Today PHP has a large user base on MS Windows 2000/NT/95/98,
You will find a huge collection of tools for PHP under MS Windows platform.
Many PHP programmers develop code on MS Windows and deploy on large linux servers
like IBM mainframe running linux, Compaq DEC Alpha and Sun sparc.
A great advantage is that since PHP also runs on UNIX/Linux, developers on
UNIX platform "cash on" the user base of PHP under MS windows as the PHP code developed
under MS Windows can be used on UNIX/linux without any code change!!
PHP itself is written in 100% "C" langauge, and hence it runs on a very wide variety of
platforms like BeOS, UNIX, MS Windows, Apple Macintosh, IBM OS/2 and on many more operating
systems.
<it><bf>PHP is very fast and is much faster than Java. For web development, forget
Java/JSP, it is PHP, PHP and PHP everywhere!! PHP is also becoming a general purpose
object oriented scripting language</bf></it>
<sect> PHP Download<label id = "PHP Download">
<p>
<itemize>
<item> PHP main site <url url="http://www.php.net">
<item> PHP resources <url url="http://ils.unc.edu/web-db/php/links.html">
<item> PHP Code Exchange - <url url="http://px.sklar.com">
<item> Vex Net <url url="http://www.vex.net/php">
</itemize>
Mirror sites are in many countries like www.COUNTRYCODE.php.net, where
COUNTRYCODE is like us, fe, sk etc.
<itemize>
<item> <url url="http://www.fe.de.php.net">
<item> <url url="http://www.sk.php.net">
<item> <url url="http://php.iquest.net/">
<item> Questions e-mail to :
<htmlurl url="mailto:rasmus@lerdorf.on.ca"
name="rasmus@lerdorf.on.ca">
</itemize>
<sect1> PHP Installation on Microsoft Windows 95/98/NT/2000<label id = "PHP Installation">
<p>
PHP is <bf>IMMENSELY POPULAR</bf> on Microsoft Windows platform and is <bf>surprisingly
more popular</bf> than Microsoft's own ASP web scripting language!! A major reason
for popularity is that PHP is a <bf>object oriented scripting</bf> language whereas ASP is not.
PHP has a large collection of re-usable classes (objects).
PHP runs lot faster than ASP on MS Windows and has more features and functionalities
than Microsoft ASP.
PHP is much more robust, reliable and powerful than ASP.
And the user base of PHP is extremely large because PHP runs on MS Windows,
Linux, Mac OS and all UNIX'es.
Greatest advantage of
PHP is that you can develop on MS Windows and deploy on Linux or UNIX and vice versa!!
There are more PHP users under MS Windows98/NT/2000 than on any other operating system!!
Because there is so much demand for PHP on MS Windows 98/NT/2000, a ready to
install executable is made and you simply double-click on the exe file to
automatically install PHP in just 2 minutes. Download the PHP executable
install file from
<itemize>
<item> MS Windows exe installer for PHP <url url="http://php.weblogs.com/easywindows">
<item> Lots of info on PHP on MS Windows platform <url url="http://php.weblogs.com">
<item> Install and config of PHP on
MS Windows <url url="http://www.php.net/manual/install-windows95-nt.php">
<item> PHP Triad installs a complete PHP server environment on Windows platforms
<url url="http://www.phpgeek.com">
</itemize>
<sect1> Apache Webserver Quick-Install (10 seconds) on Microsoft
Windows 95/98/NT/2000<label id = "apache">
<p>
You need a web-server to run the PHP on MS Windows. You can use MS IIS web server
or you can use free Apache web-server for MS Windows 95/98/NT/2000. To save you
lot of time here is the ready-to-install setup.exe file for apache
for Windows platform:
PHPTriad which is Apache+PHP+MySQL single package is at
<url url="http://www.phpgeek.com/phptriad.php">
and at <url name="mirrorsite" url="http://sourceforge.net/projects/phptriad">.
I very strongly recommend PHPTriad as it is immensely popular among MS Windows
users (millions of downloads).
Apache binaries -
<url url="http://httpd.apache.org/dist/httpd/binaries/win32">
<sect1> SQL server for Microsoft
<p>
SQL server can be on a seperate box which need not be running MS Windows.
You also need a SQL server for doing web development. I recommend that you
install Redhat Linux on a very old PC like (Pentium or 486 box) and install the
<url name="PostgreSQL" url="http://www.geocities.com/alavoor/HOWTO/pgsql/PostgreSQL-HOWTO.html">
RPMs on it. You do not need any windows graphics for a database server
and at console mode startup the
<url name="PostgreSQL" url="http://www.geocities.com/alavoor/HOWTO/pgsql/PostgreSQL-HOWTO.html">
server.
<url name="PostgreSQL" url="http://www.geocities.com/alavoor/HOWTO/pgsql/PostgreSQL-HOWTO.html">
is about <bf>3 times </bf>
faster than Oracle or MS SQL server.
The PostgreSQL support code for PHP was written by Adam Sussman
<htmlurl url="mailto: asussman@vidya.com"
name="asussman@vidya.com">
You can also order ready-to-go cheap Linux boxes from -
<itemize>
<item> Egghead <url name="Egghead" url="http://www.egghead.com">,
click on Auctions and Linux boxes, you get best deals in live Auctions.
<item> Goto <url name="LinuxHardware" url="http://lhd.datapower.com"> and click ComputerSystems,
<url name="LinuxOnline" url="http://www.linux.org/hardware">,
Linux hardware <url name="Crynwr" url="http://linux.crynwr.com">,
Linux <url name="HarwareNet" url="http://www.linuxhardware.net/vendors.html">
<item>
US <url name="Land5" url="http://www.land-5.com/CustomPage4.html">,
US <url name="QLiTech" url="http://www.qlitech.net/products/servers/athlon.html">,
US <url name="CompaqLinux" url="http://www.compaq.com/products/servers/linux">,
US <url name="VAlinux" url="http://www.valinux.com">,
US <url name="StoreAnywhere" url="http://www.storeanywhere.com">
<item> In Europe :
UK <url name="GBdirect" url="http://www.gbdirect.co.uk/linux">,
UK <url name="MultiT" url="http://www.multithread.co.uk">,
Hungary <url name="Leonardo" url="http://www.leonardo.co.hu">,
Belgium <url name="Mind" url="http://mind.be">,
Germany <url name="Spier" url="http://www.spier.be">
<item> DEC alpha linux <url name="DECalpha" url="http://www.alphalinux.org./hardware">
and <url name="CompaqAlphaLinux" url="http://www.compaq.com/AlphaServer/linux/index.html">
</itemize>
You can also get
<url name="PostgreSQL" url="http://www.geocities.com/alavoor/HOWTO/pgsql/PostgreSQL-HOWTO.html">
for Windows NT/2000 from <url url="http://www.askesis.nl">.
See also the
<url name="PostgreSQL" url="http://www.geocities.com/alavoor/HOWTO/pgsql/PostgreSQL-HOWTO.html">
howto at
<url name="pgsql-howto" url="http://www.geocities.com/alavoor/HOWTO/pgsql/PostgreSQL-HOWTO.html">
<sect1> ASP To PHP Converter - Migration From ASP2PHP
<p>
After installing PHP, you may want to migrate all the Microsoft ASP programs
to PHP. See the chapter <ref name="ASP2PHP" id="asp2php">.
<sect1> PHP Installation on UNIX'es and others<label id = "PHP Installation">
<p>
See the installation guide and instructions at
PHP main site <url url="http://www.php.net"> or INSTALL file
in the downloaded package itself.
<sect1> PHP Installation on Apple Macintosh<label id = "applemac">
<p>
Apple Macintosh is Unix like operating system. And actually it's father is FreeBSD.
It picked up many titbits from other Unices and is quite powerful OS.
See the Unix history at <url name="Unix Family Tree" url="http://perso.wanadoo.fr/levenez/unix">
and click on the item 12 to see the Apple Mac position
at <url name="Apple Mac tree" url="http://perso.wanadoo.fr/levenez/unix/history.html#12">.
The installation and use of PHP on Apple Mac will be very similar to that of on Unix OS.
<sect> Quick Start steps <label id = "quickstart">
<p>
To implement a project in object oriented PHP do -
<itemize>
<item> First you need connection to database sql servers - use one of these:
<itemize>
<item> <bf>ADODB</bf> (Active Data Objects Data Base)
<url url="http://php.weblogs.com/ADODB">
<item> <bf>Metabase</bf> (Database independent access and management)
<url url="http://phpclasses.upperdesign.com/browse.html/package/20">
</itemize>
<p>
<item> Second you need generic PHP classes to create forms, tables and other
HTML objects. Get these from
<bf>PHP classes</bf> at <url url="http://phpclasses.upperdesign.com">.
See also the Top downloaded classes from
<url name="Top PHP classes" url="http://phpclasses.upperdesign.com/browse.html/top">.
And see Form classes, template classes at
the site <url name="corporate Intranet/Internet" url="http://www.milkywaygalaxy.freeservers.com">
<p>
<item> Third, design and create your own PHP classes by inheriting from the
generic
<url name="PHP classes" url="http://phpclasses.upperdesign.com">.
<p>
<item> Fifth, use IDE tools from <ref id="PHP IDE">
<p>
<item> Most of your PHP code should be in classes for easy code maintainence and re-usability.
</itemize>
See also
<url name="Aldev's PHP classes" url="http://phpclasses.upperdesign.com/browse.html/author/35463">
<sect> Major Features of PHP <label id = "phpfeatures">
<p>
<itemize>
<item>Standard CGI, FastCGI and Apache module support -
As a standard CGI program, PHP can be installed on any
UNIX machine running any UNIX web server. With support for
the new FastCGI standard, PHP can take advantage of the
speed improvements gained through this mechanism. As an
Apache module, PHP becomes an extremely powerful and
<bf>lightning fast</bf> alternative to CGI programmimg.
<item> Access Logging -
With the access logging capabilities of PHP, users can
maintain their own hit counting and logging. It does not use
the system's central access log files in any way, and it
provides real-time access monitoring. The Log Viewer Script
provides a quick summary of the accesses to a set of pages
owned by an individual user. In addition to that, the package
can be configured to generate a footer on every page which
shows access information. See the bottom of this page for an
example of this.
<item> Access Control -
A built-in web-based configuration screen handles access
control configuration. It is possible to create rules for all
or some web pages owned by a certain person which place
various restrictions on who can view these pages and how they
will be viewed. Pages can be password protected, completely
restricted, logging disabled and more based on the client's
domain, browser, e-mail address or even the referring
document.
<item> PostgresSQL Support -
Postgres is an advanced free RDBMS. PHP supports embedding
PostgreSQL "SQL queries" directly in .html files.
<item> RFC-1867 File Upload Support -
File Upload is a new feature in Netscape 2.0. It lets users
upload files to a web server. PHP provides the actual Mime
decoding to make this work and also provides the additional
framework to do something useful with the uploaded file once
it has been received.
<item> HTTP-based authentication control -
PHP can be used to create customized HTTP-based
authentication mechanisms for the Apache web server.
<item> Variables, Arrays, Associative Arrays -
PHP supports typed variables, arrays and even PERL-like
associative arrays. These can all be passed from one web page
to another using either GET or POST method forms.
<item> Conditionals, While Loops -
PHP supports a full-featured C-like scripting language.
You can have if/then/elseif/else/endif conditions as well as
while loops and switch/case statements to guide the logical
flow of how the html page should be displayed.
<item> Extended Regular Expressions -
Regular expressions are heavily used for pattern matching,
pattern substitutions and general string manipulation. PHP
supports all common regular expression operations.
<item> Raw HTTP Header Control -
The ability to have web pages send customized raw HTTP
headers based on some condition is essential for high-level
web site design. A frequent use is to send a Location: URL
header to redirect the calling client to some other URL. It
can also be used to turn off cacheing or manipulate the last
update header of pages.
<item> On-the-fly GIF image creation -
PHP has support for Thomas Boutell's GD image library
which makes it possible to generate GIF images on the fly.
<item> ISP "Safe Mode" support -
PHP supports an unique "Safe Mode" which makes it safe to
have multiple users run PHP scripts on the same server.
<item> Many more new features are being added in newer releases of PHP.
Visit the main web site at <url url="http://www.php.net">
<item> It's Free! -
One final essential feature. The package is completely free.
It is licensed under the GNU/GPL which allows you to use the
software for any purpose, commercial or otherwise.
</itemize>
<sect1>Advantages of PHP over Java<label id = "phpvsjava">
<p>
PHP is an established server-side scripting language for creating dynamic Web pages. As a language that has been designed expressly for the Web, it brings
many features that commercial entities are looking for:
<itemize>
<item>Exceptionally short learning curve
<item>Quick development time
<item>Very high performance
</itemize>
This is essential for companies who are faced with scarce skilled programming resources and ever-tighter time to market deadlines. In addition, PHP supports
all major platforms (UNIX, Windows and even mainframes), and features native support for most popular databases. All these factors make it a very good
choice for Web development: such shops working with PHP have reported being able to hire non-programmers and have them producing usable code within
days. Programmers familiar with languages such as C, C++ or Java frequently find that they can begin programming in PHP within a few hours.
The fact that PHP was designed specifically for Web development gives it an edge as a development tool, as Intranet Design Magazine explains:
"PHP was built with the needs of Web developers in mind... Unlike other cumbersome, overhead-laden approaches, PHP is lightweight and focused on the
Web - where it can solve complex problem scenarios quicker and more easily than comparable technologies."1
Java began its life as a programming language and was initially aimed at running client-side applications inside of Web browsers. Over the last few years, the
problems associated with these "applets," as they were known, has led Sun and many other Java developers to use the language in other ways. One of the
most prominent ways is in server-side programming, allowing Web sites to connect to databases and produce other server-side applications, or "servlets."
Sun came out with Java Server Pages (JSP) as a means of writing servlets. JSP, like PHP, is highly portable across different platforms (even though PHP
supports any 32-bit or better platform, whereas JSP supports only platforms that have a Java virtual machine available). However, a beginner with no
programming background will find it exceptionally difficult to begin working with servlets,because of the complexity of the language as well as the complicated
JSP system design.
JSP's performance also leaves much to be desired: a recent survey in ZDnet's eWeek online publication found that PHP is as much as 3.7 times faster than
JSP. In the Web environment, this makes JSP a significantly worse solution - because it can perform less transactions per second, and features considerably
slower response times.
ZDnet's eWeek also noted that
"JSP is a relatively new technology and still has clear market immaturities in terms of tools, support resources and available talent."...Because JSP is based on
Java, a strongly typed language, we had to declare the types of variables we used and manually convert between types when necessary. This makes JSP the
hardest of the scripting languages we tested for nonprogrammers to learn..."
<sect2>Bad Points Of Java<label id = "badjava">
<p>
<enum>
<item> The server is under your control but you will never know what the clients will be?
MS Windows, Linux, Mac, Unix?? Java is designed for client side computing with "Applets",
"Swing" and "AWT".
<p>
<item> Java is a bad choice on the server-side! Since server OS is under your control, you need
something like PHP which runs directly without any intermediate layers like Java virtual
machine and JIT compiler. You simply select Linux, Unix or MSWindows on server-side and use PHP.
<p>
<item> Java is very complicated due to many layers like JVM, JIT, whereas PHP is quite simple,
fast and runs directly on the server operating system. This means Java technologies can never be
faster than PHP!
<p>
<item> Java technology is very bad choice on the server-side. When you have Linux on server
which is completely under your control why do you need Java?? By the way, the browser clients
never know that you are using Linux + Apache + PHP !! (The clients may think that the HTML pages
are coming from MS Windows + MS IIS !! )
<p>
<item> Use Java technology on the client-side. Use Java inside web browsers like Applets and
other client applications like Swing, AWT and others.
<p>
</enum>
<sect2>PHP works with Java<label id = "phpworksjava">
<p>
It is important to note JSP is just one language with which Java objects can be accessed. PHP also can also integrate with Java, which means that it can be
used as the scripting language for activating Java logic, just as much as JSP can. Unlike JSP, however, PHP also integrates with other component models,
such as Microsoft's COM, and adding support for new object models is extremely easy. This means PHP's extensibility is infinite. JSP, on the other hand, is
completely dependent on Java.
IBM programmer Sam Ruby uses PHP in combination with Java. Using the native Java support in PHP, Java objects can be created and used transparently,
as if they were regular PHP objects.
AuctionWatch , which enables businesses of all sizes to benefit from dynamic pricing environments, has over 2.6 million unique visitors per month; 300K+
registered users; 1.2 million+ auctions launched every month. They tried to use Java, but opted for PHP because it's easier to use and much faster to develop
with. For further information, please
contact Ben Margolin, Director of Seller Services for AuctionWatch (ben@auctionwatch.com).
Programming consultant Reuven Lerner has made some comparisons
among the languages. His view of PHP is summarized as follows:
"The language is easy to learn. Graphic artists and Web designers might claim that they are not programmers, but the fact is that they're doing increasingly
large projects in JavaScript, VBScript, and other simple programming languages. PHP is much more regular and well-defined than PERL, and is much easier for
new programmers to grasp than Java. Indeed, PHP seems like a server-side version of what JavaScript could have been, but isn't. Someone with little or no
programming experience can learn PHP and work with it after a very short period of time. This is probably true for VBScript, but certainly not for PERL or
Java....PHP is a truly remarkable and powerful system.
I can see why it has become a popular system for producing Web sites.... I think that it will be a very strong competitor against Java and JSPs, and will rise
significantly in my recommendations for clients and internal use."
<sect2>PHP: Growing by the month<label id = "phpgrowth">
<p>
JSP enjoys the backing of Sun; hence its constant media attention. It is interesting to note that despite the lack of any publicity campaign, PHP's popularity is
growing at a monthly rate of 8-11%, a percentage far greater than the Internet's 4% monthly growth -- as the demand for server-based applications has
risen. More than 6.5 million sites use PHP (Netcraft May 2001 survey). PHP is used on 39% of Apache servers; PERL trails fourth, with 11% of the market.
Apache maintains 59% of the Web server market; Microsoft IIS is second, with 28% of market share (E-Soft Inc./SecuritySpace's May 2001 report).
Prominent corporations using PHP include Unilever, Philips, NTT, Cisco, Japan Airlines, Air Canada, Lufthansa, GE Marketplace, Wallstreet:Online Germany;
AuctionWatch, VillageVoice, Dialpad and BMC.
<enum>
<item>Intranet Design Magazine: PHP From an IT Manager's Perspective, Jun 4, 2000.
<url url="http://linuxtoday.com/news_story.php3?ltsn=2000-06-04-002-04-NW-HL-SW">
<p>
<item>eWEEK: Four scripting languages speed development, October 30, 2000.
<url url="http://www.zdnet.com/eweek/stories/general/0,11011,2646052,00.html">
</enum>
<sect>Brief History of PHP
<p>
PHP began life as a simple little cgi wrapper written in PERL.
The name of this first package was Personal Home Page Tools, which
later became Personal Home Page Construction Kit.
Old name is Professional Home Pages (PHP) and new name is PHP Hypertext Pre-Processor.
A tool was written to easily embed SQL queries into web pages. It
was basically another CGI wrapper that parsed SQL queries and
made it easy to create forms and tables
based on these queries. This tool was named FI (Form Interpreter).
PHP/FI version 2.0 is a complete rewrite of these two packages combined
into a single program.
It evolved to a simple programming language embedded inside HTML files.
PHP eliminates the need for numerous small PERL cgi programs
by allowing you to place simple scripts directly in your HTML files. This
speeds up the overall performance of your web pages since the overhead of
forking PERL several times has been eliminated.
It also makes it easier to manage large web sites by placing
all components of a web page in a single html file.
By including support for various databases, it also makes it
trivial to develop database enabled web pages. Many people find the
embedded nature much easier to deal with than trying to create separate
HTML and CGI files.
Now PHP/FI is renamed as PHP.
<sect>A Simple Example
<p>
Suppose you have a form:
<tscreen><verb>
<FORM ACTION="/cgi-bin/php.cgi/~userid/display.html" METHOD=POST>
<INPUT TYPE="text" name="name">
<INPUT TYPE="text" name="age">
<INPUT TYPE="submit">
<FORM>
</verb></tscreen>
Your display.html file could then contain something like:
<tscreen><verb>
&lt ?echo "Hi &dollar name, you are &dollar age years old!<p>" &gt
</verb></tscreen>
It's that simple! PHP automatically creates a variable for each form
input field in your form. You can then use these variables in the ACTION
URL file.
The next step once you have figured out how to use variables is to start
playing with some logical flow tags in your pages. For example, if you
wanted to display different messages based on something the user inputs,
you would use if/else logic. In our above example, we can display different
things based on the age the user entered by changing our display.html to:
<tscreen><verb>
<?
if($age>50);
echo "Hi $name, you are ancient!<p>";
elseif($age>30);
echo "Hi $name, you are very old!<p>";
else;
echo "Hi $name.";
endif;
>
</verb></tscreen>
PHP provides a very powerful scripting language which will do much more
than what the above simple example demonstrates. See the section on the
PHP Script Language for more information.
You can also use PHP to configure who is allowed to access your pages.
This is done using a built-in configuration screen. With this you could for
example specify that only people from certain domains would be allowed to
see your pages, or you could create a rule which would password protect
certain pages. See the Access Control section for more details.
PHP is also capable of receiving file uploads from any RFC-1867
compliant web browser. This feature lets people upload both text and binary
files. With PHP's access control and logical functions, you have full
control over who is allowed to upload and what is to be done with the file
once it has been uploaded. See the File Upload section for more details.
PHP has support for the PostgreSQL database package. It supports
embedded SQL queries in your .HTML files.
PHP also has support for the mysql database package. It supports
embedded SQL queries in your .HTML files.
<sect> SOAPX4 and PhpXMLP <label id = "soap">
<p>
SOAP is an XML-based protocol for messaging and RPC-style communication between two processes.
The World Wide Web Consortium's XML Protocol (XP) Working Group is working on a SOAP
standard, which will be called XP.
The SOAPX4 (Simple Object Access Protocol) implementation for PHP is at
<url url="http://dietrich.ganx4.com/soapx4">.
Alternate SOAP implementation is at <url url="http://sourceforge.net/projects/phpxmlp">.
<sect1>XML/XSLT Publishing Engine<label id = "xmlengine">
<p>
Krysalis is the XML/XSLT publishing engine,
inspired from Cocoon but adapted to the PHP technology.
InterAKT has developed Krysalis to achieve what the next generation of
web services have to offer - the complete separation of the information,
application logic and presentation layer.
Krysalis is an open-source PHP development platform, based on the
XML/XSLT core. It reused most of PHAkt code to create the Krysalis taglib library.
Major features are:
<itemize>
<item>Dynamic XML support.
<item>Dynamic PDF generation.
<item>Sitemap description with regular expressions.
<item>PXP page caching.
<item>Multiple transformation pipelines.
<item>Multiple connection types to various databases (ADODB).
</itemize>
Please visit the Krysalis site for more information
<url url="http://www.interakt.ro/products/Krysalis">.
<sect> PHP Libraries <label id = "phplibs">
<p>
The PHP is a object-oriented scripting language. Hence PHP code is
<bf>"classes, classes, classes and classes"</bf>. When you write PHP code you must
design your classes such that they are re-usable or they use existing PHP classes.
There are hundreds of PHP classes already written and ready to use. There are
classes for accessing databases, classes for generating XML, HTML forms, classes for
creating tables, forms and other HTML objects. If you write some generic classes then
please upload to sites. By year 2005, there will be more than hundred million
re-usable PHP classes. Advantage of PHP classes are they provide - data hiding,
inheritance, encapsulation, reliability, reusability and polymorphism.
The most important PHP sites are <bf>PHP classes</bf> and <bf>PEAR</bf> as given below.
<sect1>Classes and PEAR <label id = "pear">
<p>
Visit the following web sites which have large collections of
ready to use PHP class libraries.
<itemize>
<item> <bf>PHP classes</bf> are at <url url="http://phpclasses.upperdesign.com">.
<p>
<item> <bf>PEAR (PHP Extension and Application Repository)</bf> is a code repository
for PHP extensions and PHP library code similar to PERL's CPAN and is at
<url url="http://pear.php.net"> and
<url name="mirror" url="http://lxr.php.net/source/php4/pear">
linux <url name="php-pear-rpms" url="http://rpmfind.net/linux/rpm2html/search.php?query=pear">
and <url name="pear-tutorials" url="http://php.weblogs.com/php_pear_tutorials">.
<p>
<item> <bf>ADODB</bf> (Active Data Objects Data Base)
<url url="http://php.weblogs.com/ADODB"> :
PHP's database access functions are not standardised. Every database extension uses a different
and incompatibile API. This creates a need for a database class library to hide the
differences between the different databases (encapsulate the differences) so we can easily
switch databases.
ADODB currently support MySQL,
<url name="PostgreSQL" url="http://www.geocities.com/alavoor/HOWTO/pgsql/PostgreSQL-HOWTO.html">
, Interbase, Oracle, MS SQL 7,
Foxpro, Access, ADO, Sybase and generic ODBC.
See also <url name="ADODB-manual" url="http://php.weblogs.com/ADODB_manual">.
The <url name="PhpLens" url="http://phplens.com"> is based on ADODB.
<p>
<item> <bf>Metabase</bf> (Database independent access and management)
<url url="http://phpclasses.upperdesign.com/browse.html/package/20">
<p>
<item> <bf>PHP Hot scripts</bf> <url url="http://www.hotscripts.com/PHP">
<p>
<item> Very <bf>popular PHP resources</bf> <url url="http://php.resourceindex.com">
and <url name="CGI-Resources" url="http://cgi-resources.com">
<p>
<item> PHP projects are at <url url="http://php.net/projects.php">
<p>
<item> PHP Lib Netuse <url url="http://phplib.netuse.de"> (This is deprecated, merged with PEAR)
<item> PHP widgets <url url="http://www.northern.ca/projects/phpwidgets">
<item> Generic Framework PHP4 <url url="http://sourceforge.net/projects/gpfr">
<item> Source Forge PHP Lib <url url="http://phplib.sourceforge.net">
<item> Source Forge PHP Snippets, go and click on PHP here <url url="http://sourceforge.net/snippet">
<item> E-gineer PHP lib <url url="http://e-gineer.com/articles/php-hacker">
<item> FAQ PHP <url url="http://php.faqts.com">
<item> PHP Lib <url url="http://px.sklar.com">
<item> PHP Factory <url url="http://alfalinux.sourceforge.net/phpfact.php3">
<p>
<item> PHP Builder site <url url="http://phpbuilder.com/snippet">
<item> PHP developer <url url="http://www.phpdeveloper.org">
<item> PHP newbie <url url="http://www.newbienetwork.net">
<item> PHP walrus <url url="http://www.evilwalrus.com">
</itemize>
<sect1>Other PHP Utilities <label id = "phputils">
<p>
Other PHP utilities are at :
<itemize>
<item> User Login sample: <url url="http://www.devshed.com/Server_Side/PHP/Commerce1">
<p>
<item> phpPDFtable is a class written in php to ease the creation of
tables in PDF files. It requires php (4.0 but should
run with 3.x too), and pdflib <url url="http://sourceforge.net/projects/phppdftable">
<p>
<item> Data-Admin aims to provide a PHP based interface to Database
Administration. This will not be limited to just one or two
databases. Also, the underlying class library encapsulates the
native PHP database calls allowing the programmer to use one set of fu
<url url="http://sourceforge.net/projects/dadmin">
<p>
<item> PSlib is a PHP library for generating PostScript files. It offers
an easy way of generating PostScript files: simple call PSlib functions
from within your PHP script and the PS files are created on the fly
<url url="http://sourceforge.net/projects/pslib">
<p>
<item> A complete collection of php scripts that work tightly together to
create a highly customizable, dynamic and module oriented website
<url url="http://sourceforge.net/projects/twebs">
<p>
<item> phpOpenTracker is a comprehensive solution for your site- and
visitor-tracking needs. The collected data is stored in a SQL
database, allowing complex, yet easy analysis. A powerful API for
analysis and report generation (HTML or PDF output) is included.
<url url="http://www.phpopentracker.de">
<p>
<item> PHPShopCart is a shopping-cart web application demo written in
PHP and designed to connect to a MySQL database. It was written
for the book, "A Guide to Databases under Linux" (Syngress Media) but
is available under the GNU Public License.
<url url="http://sourceforge.net/projects/phpshopcart">
</itemize>
<sect> PHPGem package
<p>
PHPGem is a PHP-script which accelerates the creation of PHP-scripts
for working with tables. It works with different SQL-servers such as
PostgreSQL, MySQL, mSQL, ODBC, and Adabas. You input a description of
and parameters for your tables' fields (field name, on/off searching
in the field, etc.), and PHPGem outputs another PHP-script which will
work with the tables (view/add/edit/delete/duplicate entries and
search). PHPGem works with multi-level nested tables. PHPGem allows
you to specify a level of access for each table and for each field for
each user. PHPGem also support images.
PHPGem is at <url url="http://sptl.org/phpgem">
<sect>PHP Application Servers<label id = "phpwebserv">
<p>
<it><bf>
The PHP applications are categorized into more than 60 groups in hotscripts.com site
at <url name="HotScripts - PHP" url="http://www.hotscripts.com/PHP/Scripts_and_Programs">.
You MUST visit this site before looking elsewhere.
</bf> </it>
<sect1>Build PHP based corporate Intranet and Internet
<p>
Visit the site <url name="corporate Intranet/Internet" url="http://www.milkywaygalaxy.freeservers.com">
for a very good comparison and listing of applications.
<sect1>Popular PHP Applications
<p>
The most popular PHP applications in the order are:
<enum>
<item> <url name="PHP-Nuke" url="http://www.hotscripts.com/Detailed/5947.html">
and the <url name="mainsite" url="http://phpnuke.org">
<item> <url name="Smarty" url="http://www.hotscripts.com/Detailed/8817.html">
and the <url name="mainsite" url="http://www.phpinsider.com/php/code/Smarty">
<item> <url name="eZ Publish" url="http://www.hotscripts.com/Detailed/7894.html">
and the <url name="mainsite" url="http://developer.ez.no/article/static/7">
<item> <url name="Mambo Portal/Content Mgmt" url="http://www.hotscripts.com/Detailed/10068.html">
and the <url name="mainsite" url="http://www.miro.com.au">
<item> <url name="PHP Content Management System" url="http://www.hotscripts.com/Detailed/8455.html">
and the <url name="mainsite" url="http://mcyra.homeip.net/homepage/phpcms/index.htm">
<item> <url name="PHP Shop" url="http://www.hotscripts.com/Detailed/4131.html">
and the <url name="mainsite" url="http://www.phpshop.org">
<item> <url name="phpWebSite" url="http://www.hotscripts.com/Detailed/9026.html">
and the <url name="mainsite" url="http://phpwebsite.appstate.edu">
<item> <url name="myPHPCalendar" url="http://www.hotscripts.com/Detailed/4182.html">
and the <url name="mainsite" url="http://myPHPCalendar.sourceforge.net">
<item> <url name="TreeMenu" url="http://www.hotscripts.com/Detailed/3704.html">
and the <url name="mainsite" url="http://apollo.spaceports.com/~refcentr/index.html">
<item> <url name="Backend" url="http://www.hotscripts.com/Detailed/5921.html">
and the <url name="mainsite" url="http://back-end.org">
<item> <url name="Typo3 Content Mgmt" url="http://www.hotscripts.com/Detailed/8392.html">
and the <url name="mainsite" url="http://www.typo3.com">
<item> <url name="E-Guest" url="http://www.hotscripts.com/Detailed/9956.html">
<item> <url name="PHProjekt" url="http://www.hotscripts.com/Detailed/7598.html">
and the <url name="mainsite" url="http://www.phprojekt.com/index.php">
<item> <url name="Phorum" url="http://www.hotscripts.com/Detailed/175.html">
and the <url name="mainsite" url="http://phorum.org">
</enum>
PHP has several tools which are given below:
<sect1>PHP Web Application Servers
<p>
The following are available for PHP:
<itemize>
<item> <bf>LogiCreate WebApp Server (for PHP)</bf>
<p>
The LogiCreate system was designed primarily with open source technologies of
Linux, Apache and PHP, LogiCreate provides a unique value in price/performance
and costs are kept reasonable. Visit <url url="http://www.logicreate.com">
and click on Download button and read the white papers there.
<item> <bf>PHP Lens</bf>
<url url="http://phplens.com">
is a rapid application development component which allows PHP developers
to dynamically and quickly create web applications that retrieve information from
databases. With phpLens, data can be presented as html tables with facilities to create,
edit, paginate, search and delete records. PHPLens uses ADODB.
See also <url name="ADODB" url="http://php.weblogs.com/ADODB">.
<p>
<item> ADODB (Active Data Objects Data Base)
<url url="http://php.weblogs.com/ADODB"> :
PHP's database access functions are not standardised. Every database extension uses a different
and incompatibile API. This creates a need for a database class library to hide the
differences between the different databases (encapsulate the differences) so we can easily
switch databases.
ADODB currently support MySQL,
<url name="PostgreSQL" url="http://www.geocities.com/alavoor/HOWTO/pgsql/PostgreSQL-HOWTO.html">
, Interbase, Oracle, MS SQL 7,
Foxpro, Access, ADO, Sybase and generic ODBC.
See also <url name="ADODB-manual" url="http://php.weblogs.com/ADODB_manual">.
<item> <bf>Metabase</bf> (Database independent access and management)
<url url="http://phpclasses.upperdesign.com/browse.html/package/20">
<p>
<item> Binary Cloud
<url url="http://www.binarycloud.com">
is an opensource, enterprise class web application platform
It provides a complete set of core services such as authentication,
permissions, database abstraction, and error handling - and a rich set of
advanced tools built on that foundation.
The system is deployed in a number of commercial installations and has
proven to be robust, scaleable, and secure.
Binarycloud is suitable for large-scale commerce and publishing projects,
or anything of similar complexity. It offers some unique security
features - such as selective encryption of database I/O - which make it
a particularly good choice for web applications that require a high level
of data security. And it's free.
<p>
<item> PEAR (PHP Extension and Application Repository) is a code repository
for PHP extensions and PHP library code similar to PERL's CPAN and is at
<url url="http://lxr.php.net/source/php4/pear">
and <url name="pear-tutorials" url="http://php.weblogs.com/php_pear_tutorials">.
<p>
<item> Midgard is Content management system is based on Apache and uses
the PHP scripting language
The main site of Midgard is at <url url="http://www.midgard-project.org">
PHP can be compiled with
Zend compiler and optimizer <url url="http://www.zend.com">. PHP runs
very fast and is about 5 to 10 times faster than Java.
See <ref id="midgardinstall" name="Midgard Installation">
<p>
<item> Ariadne
<url url="http://www.muze.nl/software/ariadne">
is a web application system. It consists of a
complete framework for the easy development and
management of web applications, using PHP. The system
uses a modular approach, using abstract interfaces for all
transactions. This results in maximum freedom to change
parts of the systems workings or add new functionality
without needing to reprogram other parts
<p>
<item> Group IT Engine
<url url="http://groupit.org">
is a turnkey group collaboration and content management engine. It
presently runs on UNIX machines using PHP and Apache. Using GroupIT you
can "Categorize your content", "Organize your contents into sections",
"Control access to your content" and many more
<url name="additional features" url="http://groupit.org/channel/features">.
<p>
<item> Ampoliros
<url url="http://www.ampoliros.com">
Ampoliros is an advanced and easy to use distributed PHP Web applications
platform, featuring a powerful Xml-Rpc and Soap interface. It is suitable
as an Internet/Intranet development and deployment system. It has a very
strong modular architecture and allows very fast deployment of web solutions.
Ampoliros is backed by Solarix, which offers customization, complete
Ampoliros based solutions, support, developer programs and other services.
</itemize>
<sect1> PHP Template Engines <label id = "template">
<p>
<itemize>
<item> Php Sitemanager - do code creation, a layout design, site implementation and site
management. Visit <url name="SiteManager" url="http://www.roadsend.com/siteManager/home/treeMenu.php">
<p>
<item> Smarty Template Engine -
is a template engine for PHP. One of the unique aspects about Smarty
that sets it apart from other templating solutions is that it compiles
the templates into native PHP scripts upon the first invocation. After
that, it merely executes the compiled
PHP scripts. Therefore, there is no costly template file parsing for each request.
See Smarty <url name="QuickStart" url="http://www.phpinsider.com/php/code/Smarty/QUICKSTART">
and docs about Smarty are at <url url="http://www.phpinsider.com/php/code/Smarty/docs">.
Get it from <url name="download-smarty" url="http://www.phpinsider.com/php/code/Smarty">.
<p>
<item> DreamTime Template <url url="http://www.phptemplates.org">
<p>
<item> Fast Template
<url url="http://curtisonline.net/theme/phpfast-templates-HOWTO.html">
and <url name="main-site" url="http://www.thewebmasters.net">
<p>
<item> PHP template Layout classes commercial, VH Layout <url url="http://www.vhconsultants.com">
and see <url name="this-article" url="http://www.phpbuilder.com/columns/zhang19990610.php3">
</itemize>
<sect1> PHP based Web-Portal systems <label id = "phpportals">
<p>
The following ready-made Web-Portal systems are available:
<itemize>
<item> PHP Nuke Web Portal system at <url name="PhpNuke" url="http://sourceforge.net/projects/phpnuke">
<p>
<item> DarkPortal is a Web portal system similar to PHPNuke. It is based on the
user interface style of Slashdot and other news/portal systems.
It uses a modular core as a base for adding pluggable modules to facilitate content creation and
management. Its primary goals are full separation of content from code, fully modular portal
plugins with standardized APIs, portability and database abstraction, user level theme
selection and plugin module selection, and a modular user/group hierarchy with multiple levels
of moderation and admin capabilities.
Visit <url name="DarkPortal" url="http://freshmeat.net/redir/darkportal/13912/url_homepage">
<p>
<item> CMS system <url name="ezPublish" url="http://developer.ez.no">
<p>
<item>
Mambo is a feature-rich, dynamic portal engine/content management tool based on PHP/MySQL. It
features a very powerful and extensive admin manager, and uses a modular framework for
extensibility.
Visit <url name="Mambo" url="http://www.mamboserver.com">
and <url name="mirror" url="http://www.miro.com.au">
<p>
<item> Content Management system (CMS) PostNuke at <url url="http://postnuke.com">
</itemize>
<sect> Object Oriented Features - public, private, protected <label id = "oop">
<p>
PHP scripting language provides object oriented features through the
<bf>class</bf> keyword.
Features like public, private and protected will be supported in the future
release (they are in TODO list). In the meantime, you can
use the following coding conventions to
distinguish between private, public and protected variables:
<enum>
<item> All private variables and functions always start with underscore <bf>"_"</bf>
followed by lowercase letters
like <bf>var $_myvar;</bf>
<p>
<item> All Protected variables and functions always start with <bf>"_T"</bf> followed
by lowercase letters
like <bf>var $_Tmyvar;</bf>
<p>
<item> All Public variables and functions do not start with underscore "_"
like <bf>var $myvar;</bf>
<p>
<item> All variables and functions always start with lowercase letter (no uppercase)
like <bf>var $_myvar;</bf> and NOT like <bf>var $_Myvar;</bf>
</enum>
<code>
class someabc {
var $_conn; // Private variable
var $_Tmyvar; // Protected variable
var $connMYCONNECTION; // Public variable
var $connToDb; // Public variable
var $myvar3; // Public variable
var $myvarTHISTEST; // Public variable
function _foofunction() {} // Private function
function _Tfoofunction() {} // Protected function
function foofunction() {} // Public function
}
</code>
The private, protected declarations provide the encapsulation and data-hiding.
But you must consider the following disadvantages of encapsulation:
<itemize>
<item> Encapsulation usually requires more code, hence it
sacrifices performance especially for scripting languages like PHP
<p>
<item> Encapsulation requires lots of Set/Get methods for private/protected properties.
<p>
<item> Since encapsulation unneccessarily increases the code size, it is
not recommended for scripting language like PHP.
<p>
<item> You can enforce a good degree of encapsulation by using the coding
convention suggested in this section.
</itemize>
<sect> HTML Editor <label id = "htmleditor">
<p>
HTML editors for PHP on Windows 95/NT/2000 are:
<itemize>
<item> 1st Page 2000 - Rated 1st (the best HTML editor) <url url="http://www.evrsoft.com">
<item> Cool Page - Rated 2nd <url url="http://www.coolpage.com">
<item> Coffeecup - Rated 3rd <url url="http://www.coffeecup.com/editor">
<item> Arachnophilia - Rated 4th <url url="http://www.arachnoid.com/arachnophilia/index.html">
<item> Textpad <url url="http://www.textpad.com">
and <url name="textpad-php-add-ons" url="http://www.textpad.com/add-ons/files/syntax/php4.zip">
</itemize>
The best HTML editor is <bf>1st Page 2000</bf>, and it is a excellent HTML editor.
<sect> IDE tools for PHP <label id = "PHP IDE">
<p>
Many HTML editors are supporting PHP.
In near future every HTML editors and XML editor will be supporting PHP
"Rapid Application Development" tool.
You will notice that some of the PHP editors run only on MS Windows. Yes!!
there are millions of PHP developers on MS Windows platform.
PHP is <bf>IMMENSELY POPULAR</bf> on Microsoft Windows platform and is <bf>surprisingly
more popular</bf> than Microsoft's own ASP web scripting language!!
PHP runs lot faster than ASP on MS Windows and has more features and functionalities
than Microsoft ASP.
PHP is much more robust, reliable and powerful than ASP.
There are more PHP users under MS Windows98/NT/2000 than on any other operating system!!
PHP initially started on Linux/UNIX environment but today there are more
PHP developers on MS Windows platform as compared to UNIX.
<sect1>PHP IDE <label id = "phpide">
<p>
PHP IDE tools are at :
<itemize>
<item> <bf>PHAkt</bf>The PHP support in Macromedia Dreamweaver UltraDev that allows
Ultradev Developers to create PHP sites
<url name="PHAkt" url="http://www.interakt.ro/products/PHAkt">
<item> <bf>PHP Lens</bf>
<url url="http://phplens.com">
is a rapid application development component which allows PHP developers
to dynamically and quickly create web applications that retrieve information from
databases. With phpLens, data can be presented as html tables with facilities to create,
edit, paginate, search and delete records. PHPLens uses ADODB.
See also <url name="ADODB" url="http://php.weblogs.com/ADODB">.
<item> PHP IDE and Editor "PHP Coder"
<!--
<url url="http://www.phpide.de">
and <url name="mirror" url="http://phpcoder.stsoft.cjb.net">
-->
is now renamed to Maguma and is available at
<url url="http://www.maguma.com/english/index.php">
<item> HAPEdit at <url url="http://hapedit.free.fr">
<item> Cross-platform IDE : Activestate Komodo <url url="http://www.activestate.com/Products/Komodo">
<item> Zend PHP IDE <url url="http://zend.com/store/products/zend-ide.php">
<item> IDE for PHP scripting (Web Browser) : <url url="http://www.ekenberg.se/php/ide">
<item> Nexidion PHP IDE <url url="http://www.nexidion.org">
<item> Enter in Search keyword 'PHP IDE' in Source Forge <url url="http://sourceforge.net">
<item> Color editor gvim for PHP (Win and linux)
at <url url="http://metalab.unc.edu/LDP/HOWTO/Vim-HOWTO.html">
and see also <ref id="ptags" name="ptags of PHP">
</itemize>
<sect1>PHP IDE for MS Windows only <label id = "phpidewin">
<p>
PHP IDE/editor on MS Windows platform are :
<itemize>
<item> Rated 1st (the best PHP tool on MS Windows) :
PHPTriad is a complete PHP development and server environment for
Windows. It installs PHP, Apache, MySQL, and PHPMyAdmin, both installing and setting up
the environment. PHPTriad is at
<url url="http://www.phpgeek.com/phptriad.php">
and at <url name="mirrorsite" url="http://sourceforge.net/projects/phptriad">
<item> Rated 2nd : PHP Coder <url url="http://www.php-ide.com">
<item> Rated 3rd: PHPEd (Soyal), an excellent PHP editor (MS Windows) <url url="http://soysal.free.fr/PHPEd">
<p>
<item> IDE for PHP editor (MS Windows): <url url="http://www.phpedit.com">
<item> Color editor gvim for PHP (Win and linux)
at <url url="http://metalab.unc.edu/LDP/HOWTO/Vim-HOWTO.html">
and see also <ref id="ptags" name="ptags of PHP">
<item> IDE for PHP (MS Windows) <url url="http://www.pc-service-boerner.de/PHPScriptEditor.htm">
<item> "EditPlus Text editor" win32 <url url="http://www.editplus.com"> (high
rating 5 stars)
<item> eNotepad win32 <url url="http://www.edisys.com/Products/eNotepad/enotepad.asp"> (high
rating 5 stars)
<item> PHP editor win32 <url url="http://www.chami.com/html-kit"> (high rating 5 stars)
<item> UltraEdit win32 <url url="http://www.ultraedit.com"> with PHP
word file at <url url="http://www.ultraedit.com/downloads/additional.html">
<item> ScriptWorx editor win32 <url url="http://www.softlite.net/products/scriptworx"> (rating 4.5 stars)
<item> TextPad editor win32 <url url="http://www.textpad.com"> (rating 4.5 stars)
<item> PHP editor "ASPEdit" <url url="http://www.tashcom.com/aspedit"> (rating 3.5 stars) along
with PHP code explorer <url url="http://www.tashcom.com/codex"> (rating 4.5 stars)
<item> Code-genie editor similar to UltaEdit or TextPad but smaller in size <url url="http://www.code-genie.com">
<item> HTML/PHP editor Dreamweaver <url url="http://www.dreamweaver.com" >
<item> HTML/PHP editor Homesite <url url="http://www.allaire.com/homesite" >
<item> HTML/PHP editor Hotdog <url url="http://www.hotdog.com" >
</itemize>
<sect1>PHP IDE for both MS Windows and Linux <label id = "phpwinlinux">
<p>
PHP IDE/editor for bot MS Windows and Linux platforms are :
<itemize>
<item> PHP editor (for both windows and linux/UNIX) <url url="http://www.coffeecup.com/select/editor.html"> (rating 5 stars).
<item> HTML/PHP editors Amaya <url url="http://www.w3.org/Amaya" >
<item> Folding text editor (Win and linux) <url url="http://fte.sourceforge.net">
<item> PHP Editor (Win and linux) <url url="http://www.scintilla.org">
<item> Color editor gvim for PHP (Win and linux)
at <url url="http://metalab.unc.edu/LDP/HOWTO/Vim-HOWTO.html">
and see also <ref id="ptags" name="ptags of PHP">
<item> Jed (win and linux) <url url="http://space.mit.edu/~davis/jed.html">
<p>
<item> Editors for PHP : <url url="http://www.itworks.demon.co.uk/phpeditors.htm">
<item> Editors for PHP : <url url="http://www.oodie.com/tools/index.php?view=editor">
</itemize>
<sect1>PHP IDE for Linux only <label id = "phpidelinux">
<p>
The best IDE for PHP on linux is Coffeecup Editor as given below:
<itemize>
<item> Color editor gvim for PHP (Win and linux)
at <url url="http://metalab.unc.edu/LDP/HOWTO/Vim-HOWTO.html">
and see also <ref id="ptags" name="ptags of PHP">
<item> PHP editor<url url="http://www.coffeecup.com/select/editor.html"> (rating 5 stars).
<item> HTML/PHP editors Quanta <url url="http://quanta.sourceforge.net">
<item> HTML/PHP editors Blue Fish <url url="http://bluefish.linuxave.net" >
<item> HTML editors AswEdit <url url="http://www.advasoft.com">
</itemize>
<sect1>PHP Utilities <label id = "phputil">
<p>
Zend is a server-side caching software speeds up Web site performance, maximizes hardware
resources, and improves the online experience of customers, providing a good return
on investment. Zend accelerator caches PHP scripts, helping to reduce processing time
and Web server load while enabling administrators to monitor site performance in real time.
Cost is $980 and supports Linux, Solaris and FreeBSD.
Zends provides:
<itemize>
<item> Enables IT to serve more Web site visitors with existing hardware
<item> Speeds up Web site response time
<item> Provides real-time performance monitoring
</itemize>
<itemize>
<item> Zend Optimizers <url url="http://www.zend.com">
<item> Zend Compilers <url url="http://www.zend.com" >
<p>
<item> IonCube PHP Accelerator (PHPA) <url url="http://www.php-accelerator.co.uk">
The ionCube PHP Accelerator is an easily installed PHP Zend engine extension that
provides a PHP cache, and is capable of delivering a substantial acceleration of
PHP scripts without requiring any script changes, loss of dynamic content, or
other application compromises.
<p>
<item> APC "Alternative PHP Cache" is an open-source alternative to Zend's commercial
accelerator which is at <url url="http://apc.communityconnect.com">.
<p>
<item> Lots of info on PHP on MS Windows platform <url url="http://php.weblogs.com">
<p>
<item> PHP GroupWare Apps <url url="http://www.phpgroupware.org">
<item> PHP Web Shop <url url="http://www.phpshop.org">
<item> PHP Nuke Web Portal system <url name="PhpNuke" url="http://sourceforge.net/projects/phpnuke">
</itemize>
<sect>Code Protection - Encoding Source Code <label id = "codeprotect">
<p>
If you want to distribute your PHP source code to your clients, you may
want to encode it to protect your code so that it cannot be viewed by the users.
Use encoding to hide password, encode scripts etc.
Many enterprises require securing the source code as a pre-condition for release
process.
Use one of the following Encoding tools:
<itemize>
<item> PHP encoding with Zend Encoder
<url url="http://www.zend.com/store/products/zend-encoder.php">
<p>
<item> PHP encoding with IonCube Encoder <url url="http://www.ioncube.com/encoder/index.php">
</itemize>
<sect>Convert Microsoft ASP scripts to PHP - ASP2PHP <label id = "asp2php">
<p>
To convert ASP scripts to PHP use this utility <url url="http://asp2php.naken.cc">
See also <url url="http://www.asp2php.com">
<sect>ctags for PHP<label id = "ptags">
<p>
Tags are extremely valuable and are used for navigation of source code inside the
editors like vi, emacs, CRiSP, NEdit etc... If you had
programmed a lot in C, C++ or Java you
might have used the <bf>ctags</bf> program to create tags.
To see the online manual page, type 'man ctags' at linux/UNIX bash prompt.
The latest version of <bf>ctags</bf> supports PHP language and is
available from <url url="http://ctags.sourceforge.net">.
<bf>NOTE: <it>Do NOT use the ptags given below but instead use the latest ctags
which supports PHP language. The program below is just a exercise and sample
and was created when older versions of ctags did not support PHP. The listing
below is kept for historical reasons (a musuem).</it> </bf>
The <bf>ptags</bf> program for PHP is given below, which you can
use to create the tags for PHP source code. Your <bf>productivity will
improve 3 to 4 times</bf> if you use <bf>ptags</bf>.
See also Vim color text editor for PHP, C, C++
at <url url="http://metalab.unc.edu/LDP/HOWTO/Vim-HOWTO.html">
<code>
// Save this file as ptags.cpp and compile by
// g++ -o ptags ptags.cpp
//*****************************************************************
// Copyright policy is GNU/GPL but additional request is
// that you include author's name and email on all copies
// Author : Al Dev Email: alavoor[AT]yahoo.com
// Usage : ptags *.php3 *.inc
// This will generate a file called tags
//*****************************************************************
#include <iostream.h>
#include <fstream>
#include <stdio.h> // for sprintf
#include <stdlib.h> // for system
#include <string.h> // for memset
#include <ctype.h> // for isspace
#define BUFF_LEN 1024
#define LOCATION 9
char *ltrim(char *dd);
char *rtrim(char *ee);
main(int argc, char **argv)
{
if (argc < 2)
{
cerr << "\nUsage: " << argv[0] << " file .... " << endl;
exit(0);
}
char fname[100] = "tag_file.out";
FILE *fpout;
ofstream fout(fname);
if (fout.fail())
{
cerr << "\nError opening file : " << fname << endl;
exit(-1);
}
//fpout = fopen(fname, "w");
for (int ii = 1; ii < argc; ii++)
{
/*
char buff[2024];
sprintf(buff, "\\rm -f %s; ls %s > %s 2>/dev/null", outfile, argv[1], outfile);
cout << "\nbuff = " << buff << endl;
system(buff);
fclose(fp);
*/
FILE *fpin = NULL;
fpin = fopen(argv[ii], "r");
if (fpin == NULL)
{
cerr << "\nError opening file : " << argv[ii] << endl;
exit(-1);
}
char buff[BUFF_LEN + 100];
memset(buff, 0, BUFF_LEN +10);
for ( ; fgets(buff, BUFF_LEN, fpin) != NULL; )
{
char aa[BUFF_LEN + 100];
char aapointer[BUFF_LEN + 100];
memset(aa, 0, BUFF_LEN +10);
strcpy(aa, buff);
strcpy(aapointer, ltrim(aa));
strcpy(aa, aapointer);
// Remove the trailing new line..
{
int tmpii = strlen(aa);
if (aa[tmpii-1] == '\n')
aa[tmpii-1] = 0;
}
//cout << "aa is : " << aa << endl;
//cout << "aapointer is : " << aapointer << endl;
if (strncmp(aa, "function ", LOCATION) != 0)
continue;
//cout << buff << endl;
// Example tags file output is like -
// al2 al.c /^al2()$/;" f
{
char bb[BUFF_LEN + 100];
memset(bb, 0, BUFF_LEN +10);
strcpy(bb, & aa[LOCATION]);
char *cc = bb;
while (cc != NULL && *cc != '(')
*cc++;
*cc = 0;
cc = rtrim(bb);
//cout << "bb is : " << bb << endl;
//cout << cc << "\t" << argv[ii] << "\t" << "/^" << aa << "$/;\"\tf" << endl;
fout << cc << "\t" << argv[ii] << "\t" << "/^" << aa << "$/;\"\tf" << endl;
//fprintf(fpout, "%s\t%s\t/^%s$/;\"f\n", cc, argv[ii], aa );
}
memset(buff, 0, BUFF_LEN +10);
}
fclose(fpin);
}
fout.flush();
fout.close();
//fclose(fpout);
// Sort and generate the tag file
{
char tmpaa[1024];
sprintf(tmpaa, "sort %s > tags; \\rm -f %s", fname, fname);
system(tmpaa);
}
}
char *ltrim(char *dd)
{
if (dd == NULL)
return NULL;
while (isspace(*dd))
dd++;
return dd;
}
char *rtrim(char *ee)
{
if (ee == NULL)
return NULL;
int tmpii = strlen(ee) - 1;
for (; tmpii >= 0 ; tmpii--)
{
if (isspace(ee[tmpii]) )
{
//cout << "\nis a space!!" << endl;
ee[tmpii] = 0;
}
}
return ee;
}
</code>
<sect> PHP documenter (like Javadoc) <label id = "phpdoc">
<p>
<itemize>
<item> The phpDocumentor is a script for creating documentation from comments in php code.
It is at <url url="http://phpdocu.sourceforge.net">.
<p>
<item> The <url name="Doxygen documentation" url="http://www.stack.nl/~dimitri/doxygen"> system
can be used along with this
<url name="Doxygen PHP PERL" url="http://www.stack.nl/~dimitri/doxygen/download.html#latestman">
script. Download Doxygen and the PERL script from download page.
<p>
<item> PHPXref is a small PERL script to make working with the source code
of a large PHP site somewhat easier.
Cross references functions, variables and database tables defined
and used across your various PHP files
Generates documentation for each function defined in the
PHP files by utilizing formatted comments placed next to each function
The output is a tree of HTML files that can be
downloaded and browsed on a local machine without having to setup a web server, etc.
It is at <url url="http://phpxref.sourceforge.net">.
</itemize>
<sect> Debugging PHP <label id = "debugphp">
<p>
You can use one of the following debuggers.
List of PHP debuggers :
<itemize>
<item> <url url="http://download.php.net/manual/en/debugger.php">.
<item> <url url="http://dd.cron.ru/dbg">
<item> Zend-IDE has PHP debugger <url url="http://www.zend.com/store/products/zend-ide.php">
<item> Soysal editor has PHP debugger <url url="http://www.soysal.com/PHPEd">
<item> APD (Advanced PHP Debugger) <url url="http://apd.communityconnect.com">
<item> PHP symbolic debugger <url url="http://members.ozemail.com.au/~djf01/body.html">
and at <url url="http://freshmeat.net/projects/body-phpdebugger">
<item> Cross-platform IDE : Activestate Komodo <url url="http://www.activestate.com/Products/Komodo">
<item> The PHP Symbolic Debugger called <url name="Body" url="http://members.ozemail.com.au/~djf01/body.html">
<item> PHP Debugger called 'phpCodeSite' is available at <url url="http://phpcodesite.phpedit.com">
and see also <ref id="Appendix C" name="Appendix C">
<item> Code crusader <url url="http://www.newplanetsoftware.com/jcc">
<item>PHP Debugger is available at <url url="http://www.phpdebug.com">
</itemize>
<sect1> Debug with FILE and LINE
<p>
To debug PHP programs create a file "debug2.inc" having the
following functions :
<code>
<?php
/* define this variable, to prevent double declaration. */
if (!defined("_DEBUG2_DEFINED_"))
{
define("_DEBUG2_DEFINED_", 1 );
}
else
return; // if this file is already included then return
# file name : debug2.inc
# Functions for debuging the PHP source code
#*****************************************************************
# Copyright policy is GNU/GPL but additional request is
# that you include author's name and email on all copies
# Author : Al Dev Email: alavoor[AT]yahoo.com
#*****************************************************************
# Usage of this functions -
# In your source code put something like -
# debug2_(__FILE__, __LINE__, "f_somevariable", $f_somevariable);
# And this will generate output in debug.out file.
//function debug2_($fname, $lname, $debug_var, $debug_value=0) {}
// Give read, exec for all on directory /debug2_logs
// chmod a+rwx /debug2_logs
// But here you need to open the file in append mode.
$fp_debug2 = fopen("/debug2_logs/debug.out", "a");
if ($fp_debug2 == false)
{
print "<b>File open failed - global.var.inc<b>";
exit;
}
function debug2_($fname, $lname, $debug_var, $debug_value=0)
{
global $fp_debug2;
//print "<br> debug_value is : $debug_value <br>";
if (!$debug_value)
{
fwrite($fp_debug2, "\n ". $fname ." ". $lname .": $debug_var");
}
else
{
fwrite($fp_debug2, "\n ". $fname . " ". $lname .": $debug_var = $debug_value");
}
//print "<br> f_cookie is : $f_cookie <br>";
}
// In your first page, which is generally index.php3
// truncate the debug2_logs file in beginning of code
function init_debug_file()
{
global $fp_debug2;
$fp_debug2 = fopen("/debug2_logs/debug.out", "w");
if ($fp_debug2 == false)
{
print "<b>File open failed - global.var.inc<b>";
exit;
}
system("chmod a+rwx /debug2_logs/debug.out");
}
?>
</code>
In your PHP source code initial page which is generally index.php3, put
a line like
<code>
<?php
include ("debug2.inc");
init_debug_file();
// all other commands follows here ...
// ...........
?>
</code>
To output debug values, in your PHP source code files, put debug2_() calls
as illustrated below:
<code>
<?php
include ("debug2.inc");
debug2_(__FILE__, __LINE__, "f_somevariable", $f_somevariable);
function aa()
{
$aa = 8;
debug2_(__FILE__, __LINE__, "aa", $aa);
}
?>
</code>
When you run the PHP program the output will be traced in the file called
debug.out giving the filename, linenumber, variable name and it's value.
Use the debug2_() generously in your code. The usage of debug2_() calls
in your program will <bf>NOT</bf> have any impact on the
final production code and
also has no impact on the performance because they will be filtered out
as described below. You can use copy and paste to save time
of typing debug2() calls
or use the 'yank to buffer' feature of Vi editor and paste.
When you are done development and testing and when you are ready to
deploy on the production server, filter out the debug2_ calls from
your source code. At UNIX prompt -
<code>
bash$ mkdir production
bash$ grep -v debug2_ filea.php3 > production/filea.php3
</code>
For a large group of files -
<code>
bash$ mkdir production
bash$ ls *.php3 | while read ans
do
grep -v debug2_ $ans > production/$ans
done
</code>
And now copy the files from production to the deployment area.
<sect> General purpose programming with PHP <label id = "genphp">
<p>
PHP is very powerful and is designed such that it can replace awk, sed,
UNIX shell, PERL, Python, "C", C++ and Java.
The object oriented features of PHP is developing very rapidly and in near future
will surpass the object oriented features of Java language. All the object oriented
features are implemented in PHP via <bf>class</bf> keyword just like in Java.
If you build the CGI version of PHP, you can use it from the command
line simply typing: <tt>php filename</tt> where filename is the file you want to
parse. You can also create standalone PHP scripts by making the first
line of your script look something like:
<tscreen><verb>
#!/usr/local/bin/php -q
</verb></tscreen>
The "-q" suppresses the printing of the HTTP headers. You can leave off
this option if you like.
If you want to use PHP as a stand-alone program, just like a shell script,
"C" or PERL program, then use this technique:
<code>
bash$ php -q filename.php
bash$ php -h
bash$ php -?
bash$ /usr/bin/php -?
bash$ php -i
</code>
The command <it>php filename.php</it> will execute the file <it>filename.php</it>.
You are invoking the php program which you wrote in filename.php from the
bash commmandline instead of from the web-browser.
On Microsoft Windows platform you will bringup a MSDOS prompt from Start->Run->cmd
and put C:\Program Files\php\bin in your path environment and
<code>
C:\> php -q filename.php
C:\> php -h
C:\> php -?
or
C:\> c:\Program Files\php\bin\php filename.php
</code>
<sect1>Standalone MS Windows GUI applications using PHP<label id = "winapp">
<p>
Since PHP is general purpose scripting language and is like a <it>"glue"</it>
language, you can use it develop standalone MS Windows GUI applications.
PHP can be very easily combined with MS Windows C++ GUI classes to create
GUI applications. And developing applications with PHP is extremely fast
as it is a scripting language and it's runtime performance is also excellent
as compared with other scripting languages like PERL, Visual Basic and Python.
PHP can also be used for developing standalone GUI applications for Linux/UNIX'es.
<sect> Web Application Standards - Fusebox <label id="fusebox">
<p>
Fusebox is a FREE web application standard attempting to reduce the 70% software
failure rate by creating a standard methodology for writing
web applications. This development methodology works with ANY
web application small and large.
<itemize>
<item><url name="Fusebox Org" url="http://www.fusebox.org">
<item><url name="PHP-Fusebox development" url="http://php-fusebox.sourceforge.net">
<item><url url="http://bombusbee.com">
<item><url name="Techsedition" url="http://www.techspedition.com">
<item><url url="http://www.fusebox.com">
<item><url url="http://www.devshed.com/Server_Side/PHP/Fusebox">
</itemize>
<sect> Performance benchmarking - PHP, ASP, JSP, Coldfusion <label id="benchmarks">
<p>
It is very important to bear in mind that performance and running speed of the web scripting
engine must be given <bf>TOP PRIORITY</bf>. That is, how many
pages per second the scripting engine can pump out to the browser clients. The greater the
number of pages pumped out to clients in a given period of time, then the better
and more powerful the scripting engine is.
The
<url name="Zdnet" url="http://www.zdnet.com/enterprise/stories/linux/0,12249,2646052,00.html">
did a evaluation and benchmarking of 4 web scripting languages. During benchmarking,
the same spec
and identical cpu, memory boxes were used. Under identical conditions, it was found
that PHP was the fastest - about 3.7 times faster than JSP and
about 1.2 times faster than ASP.
Read the report at
<url name="eWeek" url="http://www.zdnet.com/enterprise/stories/linux/0,12249,2646052,00.html">
and
<url name="mirror-site" url="http://24.221.230.253/php-asp-jsp-cf.html">
The benchmark results are -
<itemize>
<item> PHP pumped out about 47 pages/second
<item> Microsoft ASP pumped out about 43 pages/second
<item> Allaire ColdFusion pumped out about 29 pages/second
<item> Sun Java JSP pumped out about 13 pages/second
</itemize>
See also PHP, ASP benchmarks at <url url="http://24.221.230.253/php-perl-benchmarks.html">
Whenever you design a web site, give attention to these important points:
<itemize>
<item> Speed of web scripting engine - how many pages per second it can pump out.
<p>
<item> KISS policy (Keep It Simple Stupid!!) - your web page should be very simple without
any fancy graphics (because web users do not want to wait for long time and they
want the information very fast). And information they read is just plain text!!
</itemize>
<!--
JSP faster than PHP?????
JSP can outperform PHP if you use the Resin engine.
http://www.caucho.com/articles/benchmark.xtp instead of Tomcat.
Neil Moomey
Web Designer
Denali Alaskan Federal Credit Union
http://www.denalifcu.org
Ph: (907) 257-7229
-->
<sect> Limitations of PHP
<p>
Everything has limitations or disadvantages and PHP is no exception.
The following are the limitations of PHP (so be <bf>WARNED !!</bf>)
<enum>
<item> PHP is NOT 100 % pure Object Oriented scripting language.
But in near future PHP may support 100% object oriented scripting (PHP may imitate
most of the syntax of Java language). PHP already imitates some features of Java language.
(In future PHP language will imitate most features of Java language and
Java programmers will <bf>love</bf> PHP. And PHP will have java keywords
like class, extends, interface, implements, public, protected, private etc..).
<item> PHP will NOT give the performance of "C" or "C++" language. Because
it is scripting language and is interpreted it will be a bit slower than
the optimized "C++" programs. For top performance, you should use "C++" and
fast-CGI with database/webserver
connection pooling and use C++ compiler optimizer "-O3" options.
Zend optimizer in PHP 4 will speed up the performance of PHP and
bring it very close to optimized "C" code .
<item> But note a point that PHP was designed for very Rapid Web-Application
Development tool. If it takes about 3 months to code a web application in C++,
then using PHP you can develop the same web application in <bf>just 4 days</bf>!!
And with zend optimizer, the speed of execution of PHP will be very
close to that of equivalent C++ program!! Hence, there is really no advantage in
using C/C++ for web development. PHP itself is written in 100% "C" language.
</enum>
On the other hand, PHP has lot of advantages and it's advantages outweigh it's
limitations -
<enum>
<item> You can very rapidly develop web applications in PHP as compile and link
is eliminated in PHP scripting language.
<item> PHP applications are very stable and do not depend on the browser
technologies unlike Javascript applications which depend on browsers.
PHP will give you the freedom to select any server platform. The browser does
not know that the HTML page is generated by PHP !!
<item> PHP has excellent database conectivity to all SQL database servers.
<item> PHP has partial support for Object oriented features
<item> PHP has C++, PERL, Javascript like syntax features and has programs like
'ptags/ctags' to navigate the source code
<item> PHP has Zend optimizer which speeds up the performance
<item> PHP runs on all UNIX'es, linux, Windows 95/NT/2000 and is more
powerful than ASP, JSP and others.
<item> PHP has a very large user base and developer base.
</enum>
<bf>See also Python: </bf> If you want 100% pure Object Oriented scripting language
than you MUST consider <bf>Python</bf>. The 'Python' is a object
oriented scripting
language from ground up. You would be using the Python Web Application server
called 'Zope' which is available at -
<url url="http://www.zope.org">
and python is at
<url url="http://www.python.org">
<sect> PHP Tutorial <label id = "PHP Tutorial">
<p>
Visit the following PHP tutorial sites -
<itemize>
<item> PHP Resource index - important PHP site - has
complete scripts, Functions, classes, documentation, examples and tutorials
<url url="http://php.resourceindex.com">
<item> PHP portal <url url="http://zend.com">
<p>
<item> <bf>PHP Hot scripts </bf>site <url url="http://www.hotscripts.com/PHP">
<p>
<item> Very <bf>popular PHP resources</bf> <url url="http://php.resourceindex.com">
and <url name="CGI-Resources" url="http://cgi-resources.com">
<p>
<item> Simple tutorial <url url="http://www.php.net/tut.php">
<item> Web Monkey <url url="http://hotwired.lycos.com/webmonkey/99/21/index2a.html">
<item> Dev Shed <url url="http://www.devshed.com/Server_Side/PHP/Introduction">
<item> PHP TidBits <url url="http://www.htmlwizard.net/resources/tutorials">
<item> PHP Builder <url url="http://www.phpbuilder.com/getit">
<item> PHP tutorials at <url url="http://www.cgi-network.net">
<item> LinuxGuruZ PHP tutorials at <url url="http://www.linuxguruz.org">
<item> PHP Wizard <url url="http://www.phpWizard.net">
</itemize>
In this tutorial we assume that your server has support for PHP activated
and that all files ending in .php are handled by PHP.
If you are using Apache then you should edit httpd.conf and make appropriate
changes to enable PHP.
Your first PHP-enabled page:
Create a file named hello.php and in it put the following lines:
<code>
<html>
<head>
&lt
title>
PHP Test&lt
/title>
&lt
/head>
<body>
<h1>
This is an example of php script.
<br>
Below, you will see one line saying 'Hello World' and 'foo is foobar':
&lt
/h1>
<?php
echo "Hello World";
$foo = "foobar";
echo "<br>foo is $foo";
?>
&lt
/body>
&lt
/html>
</code>
Copy this file hello.php to the directory known to Apache, like
<bf>/var/www/html</bf> which is also known as DocumentRoot in httpd.conf file.
Now, to run this example, bring up a web browser and type the URL
<it>http://localhost/hello.php</it> or you can type <it>http://127.0.0.1/hello.php</it>.
But make sure you bring up Apache web server on your system.
When you run the example you will get an output like:
<code>
This is an example of php script.
Below, you will see one line saying 'Hello World' and 'foo is foobar':
Hello World
foo is foobar
</code>
If you get some errors or if you see the file with tags then your Apache Web server may
not be working properly or PHP is not enabled.
Note that this is not like a CGI script.
Think of it as a normal HTML file which happens to have a set of
special tags available to you.
If you tried this example and it didn't output anything, chances are that
the server you are on does not have PHP enabled. Ask your administrator to
enable it for you.
The point of the example is to show the special PHP tag format. In this
example we used &lt ?php to indicate the start of a PHP tag. Then we put the
PHP statement and left PHP mode by adding the closing tag, ? &gt . You may jump
in and out of PHP mode in an HTML file like this all you want.
We are going to check what sort of
browser the person viewing the page is using. In order to do that we check
the user agent string that the browser sends as part of its request. This
information is stored in a variable. Variables always start with a
dollar-sign in PHP. The variable we are interested in is $HTTP_USER_AGENT.
To display this variable we can simply do:
<code>
<?php echo $HTTP_USER_AGENT; ?>
</code>
For the browser that you are using right now to view this page, this
displays:
Mozilla/4.0 (compatible; MSIE 4.01; Windows 98)
There are many other variables that are automatically set by your web
server. You can get a complete list of them by creating a file that looks
like this:
<code>
<?php phpinfo()?>
</code>
Then load up this file in your browser and you will see a page full of
information about PHP along with a list of all the variables available to
you.
You can put multiple PHP statements inside a PHP tag and create little
blocks of code that do more than just a single echo.
<code>
<?php
if(strstr($HTTP_USER_AGENT,"MSIE")) {
echo "You are using Internet Explorer<br>";
}
?>
</code>
We can take this a step further and show how you can jump in and out of PHP
mode even in the middle of a PHP block:
<code>
<?php
if(strstr($HTTP_USER_AGENT,"MSIE"))
{
?>
&lt
center>&lt
b>You are using Internet Explorer&lt
/b>&lt
/center>
<?
}
else
{
?>
&lt
center>&lt
b>You are not using Internet Explorer&lt
/b>&lt
/center>
<?
}
?>
</code>
Instead of using a PHP echo statement to output something, we jumped out of
PHP mode and just sent straight HTML. The important and powerful point to
note here is that the logical flow of the script remain intact. Only one of
the HTML blocks will end up getting sent to the viewer. Running this script
right now results in:
You are using Internet Explorer
Dealing with Forms
One of the most powerful features of PHP is the way it handles HTML forms.
The basic concept that is important to understand is that any form element
in a form will automatically result in a variable with the same name as the
element being created on the target page. This probably sounds confusing, so
here is a simple example. Assume you have a page with a form like this on
it:
<code>
<form action="action.php3" method="POST">
Your name: <input type=text name=name>
You age: <input type=text name=age>
<input type=submit>
&lt
/form>
</code>
There is nothing special about this form. It is a straight HTML form with no
special tags of any kind. When the user fills in this form and hits the
submit button, the action.php3 page is called. In this file you would have
something like this:
<code>
Hi <?php echo $name?>. You are <?php echo $age?> years old.
</code>
Surprise!! The $name and $age variables are automatically set for you by PHP !!
<sect1>Primer on PHP Sessions<label id = "sessions">
<p>
This section is written by
<htmlurl url="mailto:
yzhang@sfu.ca
" name="
Ying Zhang
">.
Before we begin, let's quickly go over the concept of a session and the reason we need it. It's hard (for me) to define what a session is exactly, so let's use an example that should be very familiar to you -- logging in to your computer and using it every day. After you log in, your computer knows who you are. Every action that you perform is done so with your name.
So what's so special about that -- we take it for granted every time we have to login to any system. What's the big deal with doing this on the web? Well, the web (or specifically, the HTTP protocol) is connectionless. That means each request made to a web server is independent of all the other requests. Whereas your computer keeps information about you in memory and knows when you log in and out, a web server doesn't. A web server simply waits for requests and sends responses.
Let's illustrate this a little bit:
<code>
John Doe __________ Jane Doe
1 | | 2
3 ------------>|web server|<---------- 4
5 |__________| 6
</code>
Let's say we only have two people, John Doe and Jane Doe, accessing MyMarket, and their actions are like this:
<enum>
<item> John looks at the product catalog.
<item> Jane looks at the product catalog.
<item> John adds an item to his basket.
<item> Jane adds an item to her basket.
<item> John goes to the checkout.
<item> Jane goes to the checkout.
</enum>
Since HTTP is connectionless, each request is completely isolated from the other requests. So how does the server know who's doing what? How does the server know that actions 1, 3, 5 are from John, and actions 2, 4, 6 are from Jane? Well, to make a long story short, the web server doesn't have to know. It can continue on happily responding to requests, session management has to be done with the backend scripting language.
What we need is a way to group together requests by the same person into the same session. This is where PHP4's session management capabilities come in. It can group together requests made from the same source (eg. client's browser) into the same session, we have to provide the smarts to associate users with sessions.
In other words, PHP4's session management can tell us requests 1, 3, and 5 belong to the same session (call it session A). Our application has to know that session A is owned by John Doe.
<sect1>Session Management in PHP4<label id = "sessionsmgmt">
<p>
PHP4 adds some session management functions that make our life easier when dealing with sessions. The ones we are interested in are:
<code>
session_start();
session_register();
</code>
session_start() is used to start up PHP4's session management capabilities; you need to call it before you use any of the other session functions. session_register() is used to tell PHP which variables to track in the session. A typical call to these functions would look like this:
session_register("SESSION");
This tells PHP to start up the session manager, and tells PHP that the variable called SESSION is a session variable. You can register as many session variables as you like, but I prefer to only register one session variable called SESSION, and anything I need persistent I put into this variable. For example, I like to say:
<code>
session_register("SESSION");
$SESSION["var1"] = 5;
$SESSION["var2"] = 6;
</code>
instead of
<code>
session_register("var1");
session_register("var2");
$var1 = 5;
$var2 = 6;
</code>
because after you register lots of session variables, you tend to forget what
they were, well, at least I do :).
Anyhow, by now you probably want to see some code in action, so create a script called session_test.php somewhere accessible, and put into it:
<code>
<?
session_start();
session_register("SESSION");
if (! isset($SESSION)) {
$SESSION["count"] = 0;
echo "<li>Counter initialized, please reload this page to see it increment";
} else {
echo "<li>Waking up session $PHPSESSID";
$SESSION["count"]++;
}
echo "<li>The counter is now $SESSION[count] ";
?>
</code>
Fire that up in your browser, the first time you hit the page, it should say " Counter initialized, please reload this page to see it increment". Each time you reload it, the counter value should increment by one. You will also see the session ID. If it does, then hurray, your PHP4 session manager works :)
So how does this work? Well, when you call session_start(), PHP4 determines a unique session ID for the client. This session ID is an MD5 hash of something (not sure what), and
is either <bf>stored in a cookie</bf> on the client's PC or is <bf>propagated in the URL</bf>.
Now each time that client makes a request, PHP4 will read this session ID and load up the data for the session. When you call session_register(), you are telling PHP4 which variables you want kept in the session. Each page that loads up, the previous values for the registered variables will be reloaded, and each time the page ends PHP4 will save the values of the registered variables.
By default, PHP keeps track of the sessions in temporary files in the /tmp
directory. If you leave this set to a world-readable directory, such as /tmp (the
default), other users on the server may be able to hijack sessions by
getting the list of files in that directory.
<bf>session.save_path</bf> defines the argument which is passed to the save
handler. If you choose the default files handler, this is the path where
the files are created. Defaults to /tmp.
Take a listings and see for yourself:
You will see something like this:
<code>
-rw------- 1 apache web 10 May 7 15:27 sess_6dd9ea8e61cd49cd3ad6de8c8b8885e8
-rw------- 1 apache web 10 May 7 19:49 sess_7d7f97afb6759948f554b00272494e52
-rw------- 1 apache web 6 May 9 01:00 sess_8ab78830e151add9d79b628958ce4eb9
-rw------- 1 apache web 31 May 9 11:41 sess_a3058a6bb1baf57f565c3844c8810f4b
-rw------- 1 apache web 30 May 9 11:42 sess_c379faad83ad3dc8ab6d22c14dbab3b4
-rw------- 1 apache web 6 May 8 01:00 sess_cd68a5054241aff1a8157c289683e869
-rw------- 1 apache web 34 May 7 15:17 sess_cd97e41912b28c44cc0481b7d978cb61
-rw------- 1 apache web 42 May 9 11:23 sess_d1285edd0c951c70b1aec17a5f602fc0
-rw------- 1 apache web 30 May 9 11:42 sess_da93f6e19b6be01257d7a6453766a23d
-rw------- 1 apache web 42 May 7 21:26 sess_e837123c1af78c538e89b47030fde337
</code>
Each one of those files is a session, let's take a look at one of them (note, you probably have to su to root to peek inside a session file). Tip: don't just cut and paste the following commands, you need to specify the name of a real file:
<code>
# more /tmp/sess_a3058a6bb1baf57f565c3844c8810f4b
</code>
You will see something like this:
<code>
SESSION|a:1:{s:5:"count";i:234;}
</code>
Does that look familiar? It should if you've ever used the serialize() and unserialize() functions in PHP. If not, don't worry about it. Anyhow, I just wanted to illustrate how sessions were stored. You can rewrite the PHP session handlers to store sessions into a database or whatever else, but that's beyond the scope of this tutorial (but it's not hard at all).
<sect1>Session Propagation<label id = "sessionpropagate">
<p>
There are two methods to propagate a session id:
<itemize>
<item>Cookies
<p>
<item>URL parameter
</itemize>
The session module supports both methods. Cookies are optimal, but since they are
not reliable (clients are not bound to accept them), we cannot rely on
them. The second method embeds the session id directly into URLs.
PHP is capable of doing this transparently when compiled with --enable-trans-sid. If you
enable this option, relative URIs will be changed to contain the session id
automatically. Alternatively, you can use the constant SID which is defined, if the
client did not send the appropriate cookie. SID is either of the form
session_name=session_id or is an empty string.
The following example demonstrates how to register a variable, and how to link
correctly to another page using SID.
Example : Counting the number of hits of a single user
<code>
&lt
html>
&lt
h1&gt
Example : Counting the number of hits of a single user&lt
/h1>
&lt
br>
&lt
php
session_register ("count");
$count++;
?>
Hello visitor, you have seen this page <?php echo $count; ?> times.<p>;
&lt
php
# the <?=SID?> is necessary to preserve the session id
# in the case that the user has disabled cookies
?>
To continue, &lt
A HREF="nextpage.php?&lt
?=SID?>">click here&lt
/A>
&lt
html>
</code>
The &lt
?=SID?> is not necessary, if --enable-trans-sid was used to compile PHP.
Note: Non-relative URLs are assumed to point to external sites and hence
don't append the SID, as it would be a security risk to leak the SID
to a different server.
<sect1>User Management and Privileges<label id = "usermgt">
<p>
Okay, we've spend enough time on PHP4's session management, all you really need to get out of that was the two functions session_start() and session_register(). Let's get back to the issue of keeping track of users.
PHP can help us keep track of sessions, and group requests from the same session together. Now, we have to do our part and associate user accounts with these sessions. We will use a variable called SESSION["user"] to keep track of user information. When a user logs in, we will put their information into this variable. As long as this variable is defined, we will assume that a user has logged in. When a user logs off, we will clear out this variable.
Specifically, we will keep the following information about the user:
<code>
SESSION["user"]["username"] This is the user's login ID (their nick name if you will), and it is how we tell users apart from each other.
SESSION["user"]["firstname"] The user's firstname.
SESSION["user"]["lastname"] The user's lastname.
SESSION["user"]["email"] The user's email address.
SESSION["user"]["priv"] The user's privilege level.
</code>
Let's talk a bit about the privilege levels. We are going to have two levels of security: (1) normal customers and (2) administrative users. Normal customers can use the system, browse through the catalog, and do other customer functions. Administrators can do everything a normal user can do, but also has the ability to perform system administrative functions. In real life, there are probably many more privilege levels that you want defined but we are going to keep things simple here.
This is all fine and dandy, but where do we get this user information from? We need to have a way to store all the users on the system, and the perfect place for that would be in the database. We're going to create a users table to hold all our users.
<sect1>Step1: Creating the Users Table<label id = "usertable">
<p>
Start up database server and login to database.
Let's create the user table:
<code>
psql> CREATE TABLE users (
-> username char(16) not null,
-> password char(32) not null,
-> priv char(5) not null,
-> firstname varchar(64) not null,
-> lastname varchar(64) not null,
-> email varchar(128) not null,
-> phone varchar(32) not null,
-> address varchar(255) not null,
-> PRIMARY KEY (username),
-> UNIQUE email (email)
-> );
</code>
Notice the constraints we've put on the users table, the username is the primary key (which makes sense, you should be able to identify a user record based on the username). The email address has a unique constraint as well because we don't want duplicate email addresses.
Now let's add a record to create the root user with the password password:
<code>
psql> INSERT INTO users VALUES (
-> 'root',
-> '5f4dcc3b5aa765d61d8327deb882cf99',
-> 'admin',
-> 'System',
-> 'Administrator',
-> 'root@mymarket.com',
-> '555-5555',
-> '123 5 Avenue'
-> );
</code>
Notice the password looks a bit wierd, <bf>5f4dcc3b5aa765d61d8327deb882cf99</bf>. This
is the MD5 hash of the the word "password", I won't go into details here, but the important thing to note is that it's a one-way algorithm and it always produces a 32 character string.
That's it, we have a users table to track our users, and one administrative account
so we can try logging in and out of the system using the example tar file
(download the example tar file from
<url url="http://www.devshed.com/Server_Side/PHP/Commerce1">
).
<sect> PHP Training & PHP Help Desk
<p>
To obtain hands on training and to attend PHP courses:
<itemize>
<item> PHP Training - 5 day hands on courses <url url="http://www.tapinternet.com/php">
<p>
<item> PHP Help Desk - 'as needed' live support (phone/email/chat),
code audits for performance and security, and more. Visit <url url="http://www.phphelpdesk.com">
</itemize>
<sect> Related URLs
<p>
Visit following locators which are related to C, C++ -
<itemize>
<item> Vim color text editor for C++, C <url url="http://metalab.unc.edu/LDP/HOWTO/Vim-HOWTO.html">
<item> SQL database server for PHP
<url name="PostgreSQL" url="http://www.geocities.com/alavoor/HOWTO/pgsql/PostgreSQL-HOWTO.html">
at
<url name="pgsql-howto" url="http://www.geocities.com/alavoor/HOWTO/pgsql/PostgreSQL-HOWTO.html">
<item> Source code control system CVS HOWTO for C++ programs <url url="http://metalab.unc.edu/LDP/HOWTO/CVS-HOWTO.html">
<item>
Linux goodies main site is at <url url="http://24.221.230.253">
and secondary site at <url url="http://www.milkywaygalaxy.freeservers.com">
Mirror sites are at -
<url name="angelfire" url="http://www.angelfire.com/country/aldev0">,
<url name="geocities" url="http://www.geocities.com/alavoor/index.html">,
<url name="virtualave" url="http://aldev0.virtualave.net">,
<url name="Fortunecity" url="http://members.fortunecity.com/aldev">,
<url name="Freewebsites" url="http://aldev.freewebsites.com">,
<url name="Tripod" url="http://members.tripod.lycos.com/aldev">,
<url name="101xs" url="http://www.101xs.com/101xs/aldev">,
<url name="50megs" url="http://aldev0.50megs.com">,
</itemize>
<sect> Other Formats of this Document
<p>
This document is published in 14 different formats namely - DVI, Postscript,
Latex, Adobe Acrobat PDF,
LyX, GNU-info, HTML, RTF(Rich Text Format), Plain-text, UNIX man pages, single
HTML file, SGML (Linuxdoc format), SGML (Docbook format), MS WinHelp format.
This howto document is located at -
<itemize>
<item> <url url="http://www.linuxdoc.org"> and click on HOWTOs and search
for howto document name using CTRL+f or ALT+f within the web-browser.
</itemize>
You can also find this document at the following mirrors sites -
<itemize>
<item> <url url="http://www.caldera.com/LDP/HOWTO">
<item> <url url="http://www.linux.ucla.edu/LDP">
<item> <url url="http://www.cc.gatech.edu/linux/LDP">
<item> <url url="http://www.redhat.com/mirrors/LDP">
<item> Other mirror sites near you (network-address-wise) can be found at
<url url="http://www.linuxdoc.org/mirrors.html">
select a site and go to directory /LDP/HOWTO/xxxxx-HOWTO.html
</itemize>
<itemize>
<item>
You can get this HOWTO document as a single file tar ball in HTML, DVI,
Postscript or SGML formats from -
<url url="ftp://www.linuxdoc.org/pub/Linux/docs/HOWTO/other-formats/">
and <url url="http://www.linuxdoc.org/docs.html#howto">
<p>
<item>Plain text format is in: <url url="ftp://www.linuxdoc.org/pub/Linux/docs/HOWTO">
and <url url="http://www.linuxdoc.org/docs.html#howto">
<p>
<item>Single HTML file format is in:
<url url="http://www.linuxdoc.org/docs.html#howto">
<p> Single HTML file can be created with command (see man sgml2html) -
sgml2html -split 0 xxxxhowto.sgml
<p>
<item>Translations to other languages like French, German, Spanish,
Chinese, Japanese are in
<url url="ftp://www.linuxdoc.org/pub/Linux/docs/HOWTO">
and <url url="http://www.linuxdoc.org/docs.html#howto">
Any help from you to translate to other languages is welcome.
</itemize>
The document is written using a tool called "SGML-Tools" which can be got from -
<url url="http://www.sgmltools.org">
Compiling the source you will get the following commands like
<itemize>
<item>sgml2html xxxxhowto.sgml (to generate html file)
<item>sgml2html -split 0 xxxxhowto.sgml (to generate a single page html file)
<item>sgml2rtf xxxxhowto.sgml (to generate RTF file)
<item>sgml2latex xxxxhowto.sgml (to generate latex file)
</itemize>
<sect1> Acrobat PDF format <label id="acrobatpdf">
<p>
PDF file can be generated from postscript file using
either acrobat <bf>distill</bf> or <bf>Ghostscript</bf>.
And postscript file is generated
from DVI which in turn is generated from LaTex file.
You can download distill software from <url url="http://www.adobe.com">. Given below
is a sample session:
<code>
bash$ man sgml2latex
bash$ sgml2latex filename.sgml
bash$ man dvips
bash$ dvips -o filename.ps filename.dvi
bash$ distill filename.ps
bash$ man ghostscript
bash$ man ps2pdf
bash$ ps2pdf input.ps output.pdf
bash$ acroread output.pdf &
</code>
Or you can use Ghostscript command <bf>ps2pdf</bf>.
ps2pdf is a work-alike for nearly all the functionality of
Adobe's Acrobat Distiller product: it
converts PostScript files to Portable Document Format (PDF) files.
<bf>ps2pdf</bf> is implemented as a very small command script
(batch file) that invokes Ghostscript, selecting a special "output device"
called <bf>pdfwrite</bf>. In order to use ps2pdf, the pdfwrite
device must be included in the makefile when Ghostscript was compiled;
see the documentation on building Ghostscript for details.
<sect1> Convert Linuxdoc to Docbook format <label id="linuxdoc2docbook">
<p>
This document is written in linuxdoc SGML format. The Docbook SGML format
supercedes the linuxdoc format and has lot more features than linuxdoc.
The linuxdoc is very simple and is easy to use. To convert linuxdoc SGML
file to Docbook SGML use the program <bf>ld2db.sh</bf> and some PERL scripts.
The ld2db output is not 100% clean and you need to use the <bf>clean_ld2db.pl</bf>
PERL script. You may need to manually correct few lines in the document.
<itemize>
<item> Download ld2db program from <url url="http://www.dcs.gla.ac.uk/~rrt/docbook.html">
or from <url name="Milkyway Galaxy site" url="http://www.milkywaygalaxy.freeservers.com">
<item> Download the cleanup_ld2db.pl PERL script from
from <url name="Milkyway Galaxy site" url="http://www.milkywaygalaxy.freeservers.com">
</itemize>
The ld2db.sh is not 100% clean, you will get lots of errors when you run
<code>
bash$ ld2db.sh file-linuxdoc.sgml db.sgml
bash$ cleanup.pl db.sgml > db_clean.sgml
bash$ gvim db_clean.sgml
bash$ docbook2html db.sgml
</code>
And you may have to manually edit some of the minor errors after
running the PERL script. For e.g. you may need to put closing tag <
/Para> for each <
Listitem>
<sect1> Convert to MS WinHelp format <label id="mswinhelp">
<p>
You can convert the SGML howto document to Microsoft Windows Help file,
first convert the sgml to html using:
<code>
bash$ sgml2html xxxxhowto.sgml (to generate html file)
bash$ sgml2html -split 0 xxxxhowto.sgml (to generate a single page html file)
</code>
Then use the tool <url name="HtmlToHlp" url="http://javadocs.planetmirror.com/htmltohlpe.html">.
You can also use sgml2rtf and then use the RTF files for generating winhelp files.
<sect1> Reading various formats <label id="readformats">
<p>
In order to view the document in dvi format, use the xdvi program. The xdvi
program is located in tetex-xdvi*.rpm package in Redhat Linux which can be
located through ControlPanel | Applications | Publishing | TeX menu buttons.
To read dvi document give the command -
<tscreen><verb>
xdvi -geometry 80x90 howto.dvi
man xdvi
</verb></tscreen>
And resize the window with mouse.
To navigate use Arrow keys, Page Up, Page Down keys, also
you can use 'f', 'd', 'u', 'c', 'l', 'r', 'p', 'n' letter
keys to move up, down, center, next page, previous page etc.
To turn off expert menu press 'x'.
You can read postscript file using the program 'gv' (ghostview) or
'ghostscript'.
The ghostscript program is in ghostscript*.rpm package and gv
program is in gv*.rpm package in Redhat Linux
which can be located through ControlPanel | Applications | Graphics menu
buttons. The gv program is much more user friendly than ghostscript.
Also ghostscript and gv are available on other platforms like OS/2,
Windows 95 and NT, you view this document even on those platforms.
<itemize>
<item>Get ghostscript for Windows 95, OS/2, and for
all OSes from <url url="http://www.cs.wisc.edu/~ghost">
</itemize>
To read postscript document give the command -
<tscreen><verb>
gv howto.ps
ghostscript howto.ps
</verb></tscreen>
You can read HTML format document using Netscape Navigator, Microsoft Internet
explorer, Redhat Baron Web browser or any of the 10 other web browsers.
You can read the latex, LyX output using LyX a X-Windows front end to latex.
<sect> Copyright
<p>
Copyright policy is GNU/GPL as per LDP (Linux Documentation project).
LDP is a GNU/GPL project.
Additional requests are - Please retain the author's name, email address
and this copyright notice on all the copies. If you make any changes
or additions to this document then you please
intimate all the authors of this document.
<sect> Appendix A PHP examples <label id="Appendix A">
<sect1> PostgreSQL large object Example
<p>
Submitted by:
PHP code exchange
<htmlurl url="mailto:
px@sklar.com
" name="
px@sklar.com
">
To get this file, in the web-browser, save this file as 'Text' type
as pgsql_largeobj.lib
<code>
PX: PHP Code Exchange -
<url name="PostgreSQL" url="http://www.geocities.com/alavoor/HOWTO/pgsql/PostgreSQL-HOWTO.html">
large object access
<?
$database = pg_Connect ( "", "", "", "", "jacarta");
pg_exec ($database, "BEGIN");
$oid = pg_locreate ($database);
echo ( "$oid\n");
$handle = pg_loopen ($database, $oid, "w");
echo ( "$handle\n");
pg_lowrite ($handle, "foo");
pg_loclose ($handle);
pg_exec ($database, "COMMIT");
pg_close ($database);
?>
</code>
<sect1> User authentication Example
<p>
To get this file, in the web-browser, save this file as 'Text' type
as user_pw.lib
From the PHP 3 Manual:
Works only if PHP is an Apache module.
Instead of simply printing out the $PHP_AUTH_USER and $PHP_AUTH_PW,
you would probably want to check the username and password for
validity. Perhaps by sending a query to a
database, or by looking up the user in a dbm file.
<code>
<?php
if (!$PHP_AUTH_USER)
{
Header("WWW-authenticate: basic realm=\"My Realm\"");
Header("HTTP/1.0 401 Unauthorized");
echo "Text to send if user hits Cancel button\n";
exit;
}
else
{
echo "Hello $PHP_AUTH_USER.<P>";
echo "You entered $PHP_AUTH_PW as your password.<P>";
}
?>
</code>
<sect1> Network admin Example
<p>
To get this file, in the web-browser, save this file as 'Text' type
as network.lib
PHP: network adminstrator's best friend from <url url="http://www.phpWizard.net">
As a web-developer, you're probably used to such lovely tools as ping,
whois, nslookup etc. But what when you need one of those utilities at a
client's office and have no access to telnet? Good guess. Time to look
up the functions in the "Network" section of the PHP manual.
<bf>Socket operations: </bf>
The most important function there is fsockopen(). Using this function,
you can connect to any open port on a server and establish a socket
connection with it. The function's syntax is as following:
<code>
int fsockopen(string hostname, int port, int [errno], string [errstr]);
</code>
The first two arguments are obvious, the next two are optional and used
for error handling. The "errno" and "errstr" should be passed by reference.
"Passing by reference" means that the original variable will get
modified. Normally, the content of a variable passed to a function
wouldn't be modified.
So, you could use this function to open a connection to a webserver and
print out the headers:
<code>
function get_headers($host, $path = "/")
{
$fp = fsockopen ("$host", 80, &$errnr, &$errstr) or die("$errno: $errstr");
fputs($fp,"GET $path HTTP/1.0\n\n");
while (!$end)
{
$line = fgets($fp, 2048);
if (trim($line) == "")
$end = true;
else
echo $line;
}
fclose($fp);
}
</code>
In this example you see that you can apply any file operations (fread,
fwrite etc) to the the pointer you got using the fsockopen() call. Note
that the example realizes a HTTP/1.0 client - it won't work with
name-based virtual hosts.
<bf>Finger: </bf>
Naturally, you can also open connections to other ports. Writing a
small finger client with PHP is trivial therefore. Let's change the
example from above to query a finger daemon:
<code>
function finger ($host, $user)
{
$fp = fsockopen($host, 79, &$errno, &$errstr) or die("$errno: $errstr");
fputs($fp, "$user\n");
while (!feof($fp))
echo fgets($fp, 128);
fclose($fp);
}
</code>
<bf>Whois: </bf>
Querying a whois server uses the same concept:
<code>
// domain is like "phpwizard.net"
function whois($domain, $server="whois.internic.net")
{
$fp = fsockopen ($server, 43, &$errnr, &$errstr) or die("$errno: $errstr");
fputs($fp, "$domain\n");
while (!feof($fp))
echo fgets($fp, 2048);
fclose($fp);
}
</code>
<bf>Blocking and non-blocking operations: </bf>
But there's a problem with all those functions. They work fine if
<enum>
<item> You have a connection with low latency and
<item> If the server you're connecting to is up and
running.
</enum>
If not, your script will be busy until
it times out. The reason for this is that default socket connections
are blocking and don't time out. You can avoid these "hanging scripts"
by switching to non-blocking socket operations. The function
set_socket_blocking() does just that: it set all operations on a socket
(first parameter: socket pointer) to either blocking (second parameter:
true) or false (second parameter: false). Using non-blocking
operations, the finger function would like like this:
<code>
$fp = fsockopen($host, 79, &$errno, &$errstr) or die("$errno: [ ] $errstr");
set_socket_blocking($fp, 0);
fputs($fp, "$user\n");
$stop = time() + $timeout;
while (!feof($fp) && time() < $stop )
echo fgets($fp, 128);
fclose($fp);
</code>
Modifying these 3 functions to use non-blocking socket calls is left as
an exercise for you.
<sect> Appendix B Midgard Installation<label id="midgardinstall">
<p>
RPMs for Midgard from
<url url="http://www.midgard-project.org/download/binaries"> currently do not
include
<url name="PostgreSQL" url="http://www.geocities.com/alavoor/HOWTO/pgsql/PostgreSQL-HOWTO.html">
, and hence you need to install from the source tar
ball file .
Download the Midgard source tarball and read the INSTALL.REDHAT file -
<code>
bash# cd midgard-lib-1.4beta6
bash# ./configure --prefix=/usr/local --with-mysql=/usr/local --includedir=/usr/include/mysql --with-midgard=/usr/local --with-pgsql=/var/lib/pgsql --includedir=/usr/include/pgsql
bash# make
bash# make install
bash# ldconfig -v | grep -i midga
Copy the header files, just in case make install did not do that..
bash# cp *.h /usr/local/include
bash# cd ../mod_midgard-1.4beta5c
bash# ./configure --prefix=/usr/local --with-mysql=/usr/local --includedir=/usr/include/mysql --with-midgard=/usr --with-pgsql=/var/lib/pgsql --includedir=/usr/include/pgsql
bash# make
bash# make install
#modify apache line to correct /usr/.....
bash# vi /etc/httpd/conf/httpd.conf (or it is /etc/apache/httpd.conf)
bash# /etc/init.d/apache restart
#apache should restart!!!
bash# cd ../midgard-php-1.4beta6
bash# ./configure '--with-apxs' '--with-mysql' '--with-pgsql' '--with-midgard' --prefix=/usr/local --with-midgard=/usr/local
bash# gvim Makefile
And add -I/usr/include/pgsql to INCLUDE variable.
Also add $(INCLUDE) to $(APXS) command as below -
libphp3.so: mod_php3.c libmodphp3-so.a pcrelib/libpcre.a midgard/libphpmidgard.a
-@test -f ./mod_php3.c || test -L ./mod_php3.c || $(LN_S) $(srcdir)/mod_php3.c ./mod_php3.c
-@test -f ./mod_php3.c || test -h ./mod_php3.c || $(LN_S) $(srcdir)/mod_php3.c ./mod_php3.c
$(APXS) -c -o libphp3.so -I$(srcdir) $(INCLUDE) -I. -I/usr/local/include -I/usr/lib/glib/include -Wl,'-rpath /usr/local/lib' ./mod_php3.c libmodphp3-so.a $(APXS_LDFLAGS)
bash# make
bash# make install
#modify apache line to correct /usr/.....
# and add lines like these -
LoadModule php4_module modules/libphp4.so
AddModule mod_php4.c
LoadModule php4_module lib/apache/libphp4.so
&lt
IfModule mod_php4.c>
AddType application/x-httpd-php4 .php4
AddType application/x-httpd-php4 .php
AddType application/x-httpd-php4-source .phps
AddType application/x-httpd-php .php
&lt
/IfModule>
bash# vi /etc/httpd/conf/httpd.conf (or it is /etc/apache/httpd.conf)
bash# /etc/init.d/apache restart
#apache should restart!!!
</code>
<sect1>Testing Midgard PHP Server<label id = "testmidgard">
<p>
To test the installation do this -
Create a file in your document root directory. I usually call
it info.php and in it put this single line:
<code>
&lt
?phpinfo()?>
</code>
Then load it up in your browser: http://localhost/info.php
You should see a nice summary page showing all sorts of information
about your setup. You probably shouldn't leave this file around on
a production server, but for debugging and general info during
development, it is very handy.
<sect1>Security OpenSSL <label id = "openssl">
<p>
You may also need to get the RSA package for to enable SSL encryption from
<url url="ftp://ftp.deva.net/pub/sources/crypto/rsaref20.1996.tar.Z">
See also OpenSSL RPM package on Linux cdrom (<url url="http://www.openssl.org">
If you do not want the SSL to be enabled (or if you face any problem), then
download the source RPM of Apache-Midgard and edit the *.spec file and comment
out SSL and rebuild the RPM.
<sect> Appendix C - Debug tool phpcodesite <label id="Appendix C">
<p>
<code>
<
?php
/* phpCodeSite (Idea from CodeSite - Raize Software)
* @version 0.1b - 20001125
* @author S<>bastien Hordeaux - <
marms@marms.com>
* @licence GNU Public Licence
* Main site : http://phpcodesite.phpedit.com
*/
/*
** How does it work ?
Place a CS_EnterMethod() at the beginning of each method/function
Place a CS_ExitMethod() at the beginning of each method/function
Use CS_SendError() to log an error message
Use CS_SendNote() to log a simple note message
Use CS_SendMessage() to log a message
To log variables: CS_SendVar & CS_SendArray()
To see input data (global PHP variables) use CS_SendInputData()
*/
if(defined("FLAG_PHPCODESITE_PHP")) return FALSE;
define("FLAG_PHPCODESITE_PHP", 1);
// Start without increment
$CS_Step = 0;
CS_SetEnabled(TRUE);
// CS_SetEnabled(FALSE);
// Switch between Enable/Disable mode
function CS_SetEnabled($state){
global $CS_Enabled;
$CS_Enabled = $state;
CS_Write($CS_Enabled?"<
pre>":"<
/pre>");
}
// Add a level to the reported items
function CS_IncStep(){
global $CS_Step;
$CS_Step++;
}
// Remove a level to the reported items
function CS_DecStep(){
global $CS_Step;
$CS_Step--;
if($CS_Step <
0)
$CS_Step = 0;
}
// Log an item
function CS_Log($msg){
global $CS_Step;
for($i = 0; $i <
$CS_Step; $i++)
CS_WriteIndent();
CS_Write($msg);
}
// Write data to the target output
function CS_Write($str){
global $CS_Enabled;
if($CS_Enabled)
echo "$str";
}
// Write an indent block
function CS_WriteIndent(){
CS_Write("| ");
}
// Beginning a new method
function CS_EnterMethod($methodName){
CS_Log("--> $methodName\n");
CS_IncStep();
}
// Exit a method
function CS_ExitMethod($methodName){
CS_DecStep();
CS_Log("<
-- $methodName\n");
}
// Log a note
function CS_SendNote($note){
CS_Log("[O] $note\n");
}
// Send a simple message
function CS_SendMessage($msg){
CS_Log("[M] $msg\n");
}
// Log an error
function CS_SendError($msg){
CS_Log("<
b>[E] $msg<
/b>\n");
}
// Log a variable
function CS_SendVar($varName, $value){
if(is_array($value)){
CS_SendArray($value, $varName);
}else{
CS_Log("[L] $varName = \"$value\"\n");
}
}
// Write all global variables to the report
function CS_SendInputData(){
global $HTTP_GET_VARS, $HTTP_POST_VARS, $HTTP_COOKIE_VARS,
$HTTP_SERVER_VARS, $HTTP_ENV_VARS, $HTTP_SESSION_VARS;
CS_Write("----------------------------------------------------------\n");
CS_SendArray($HTTP_GET_VARS, "HTTP_GET_VARS");
CS_SendArray($HTTP_POST_VARS, "HTTP_POST_VARS");
CS_SendArray($HTTP_COOKIE_VARS, "HTTP_COOKIE_VARS");
CS_SendArray($HTTP_SERVER_VARS, "HTTP_SERVER_VARS");
CS_SendArray($HTTP_ENV_VARS, "HTTP_ENV_VARS");
CS_SendArray($HTTP_SESSION_VARS, "HTTP_SESSION_VARS");
CS_Write("----------------------------------------------------------\n");
}
// Log an array
function CS_SendArray($array, $arrayStr = ""){
if(!empty($arrayStr))
CS_Log("\$$arrayStr");
if(count($array) == 0){
CS_Log(" = Array()\n");
}else{
CS_Write(" = Array(\n");
while(list($key2, $value2) = each($array)){
CS_WriteIndent();
if(empty($arrayStr))
CS_WriteIndent();
CS_Log("$key2");
if(!is_array($value2))
CS_Write(" => ".htmlentities($value2)."\n");
else
CS_SendArray($value2);
}
CS_WriteIndent();
if(empty($arrayStr))
CS_WriteIndent();
CS_Log(")\n");
}
}
?>
</code>
<sect> Appendix D - PERL versus PHP debate<label id="perldebate">
<p>
PERL (Practical Extraction and Reporting Language) is kind of ancestor
of PHP. PERL is immensely powerful and is in use for a very long time,
just like "C" language. PERL can do everything that "C" language does.
You are better off programming in PERL than in "C" language!!
Most of the "C" programmers prefer to program in PERL if speed is
not that important (C programs is little faster than PERL).
PERL5 is fully OOP operational. Just because PERL can also do
everything without OOP techniques does not mean it's not OOP.
Comparing PERL to PHP, in terms of readability and
scalability, they are nearly equal although PHP has a slight
advantage for those who insist on using only client side code.
PERL is certainly easier to read than C due to it being a very high
level language. As you know, the biggest obstacle to multiple developer
maintenance is compilers from which PERL does not suffer.
PHP and PERL are equal in these ways:
<enum>
<item> High level code. English-like syntax is easy to read and logical
<item> Execution speed. As raw interpreted source code, both are very fast
(compared to VB and the like.)
<item> Ease and speed of development. As scripts, both can be developed
quickly bypassing the nasty compiler and with built-in intelligent
debuggers.
<item> Run anywhere. A dream these share which all other languages fail.
<item> Superior text processing to all other languages.
<item> Open source.
<item> Both are very well supported by whole Internet community
<item> Both are free.
</enum>
Where PHP has an advantage over PERL:
<enum>
<item> Client-side code (for those who insist on such things.)
<item> Easier to compile into EXE.
</enum>
Where PERL might have an advantage over PHP.
<enum>
<item> PERL is already installed on every web server in the world
automatically
during setup.
<item> PERL is more backward and forward compatible.
<item> PERL in all it's versions is VERY stable.
<item> PERL hooks into all existing dbase engines very easily. The
necessary
modules come with
every PERL distribution. All that is required is up-to-date drivers
which
are easy to obtain. PERL and MySQL are made for each other.
</enum>
</article>