PHP Frequently Asked Questions
This is a list of Frequently Asked Questions about PHP and their answers. If you have suggestions, corrections or additions, send them to php3 <email protected>.
- . General Information
- ".$Major.".".$Minor; ?>. What is PHP?
- ".$Major.".".$Minor; ?>. What is the relation between the versions?
- ".$Major.".".$Minor; ?>. Can I run several versions of PHP at the same time?
- ".$Major.".".$Minor; ?>. What are the differences between PHP 3 and PHP 4?
- ".$Major.".".$Minor; ?>. How did you do those pop-out windows for the Search and Mirror buttons?
- . PHP mailing lists
- ".$Major.".".$Minor; ?>. Is there a PHP mailing list?
- ".$Major.".".$Minor; ?>. Help! I can't seem to subscribe/unsubscribe to/from the mailing list!
- ".$Major.".".$Minor; ?>. Is there an archive of the mailing list anywhere?
- ".$Major.".".$Minor; ?>. What can I ask the mailing list?
- ".$Major.".".$Minor; ?>. What information should I include when posting to the mailing list?
- ".$Major.".".$Minor; ?>. When should I reply to the list?
- . Obtaining PHP
- ".$Major.".".$Minor; ?>. Where can I obtain PHP?
- ".$Major.".".$Minor; ?>. Are pre-compiled binary versions available?
- ".$Major.".".$Minor; ?>. Where can I get libraries needed to compile some of the optional PHP extensions?
- ".$Major.".".$Minor; ?>. How do I get these libraries to work?
- ".$Major.".".$Minor; ?>. I got the latest version of the PHP source code from the CVS repository on my Windows 95/NT machine, what do I need to compile it?
- ".$Major.".".$Minor; ?>. Where do I find the Browser Capabilities File?
- . Installation
- ".$Major.".".$Minor; ?>. Where should my php3.ini file be located?
- ".$Major.".".$Minor; ?>. I installed PHP using RPMS, but Apache isn't processing the PHP pages! What's going on here?
- ".$Major.".".$Minor; ?>. I installed PHP using RPMS, but it doesn't compile with the database support I need! What's going on here?
- ".$Major.".".$Minor; ?>. How do I get these libraries to work?
- . Build Problems
- ".$Major.".".$Minor; ?>. I got the latest version of PHP using the anonymous CVS service, but there's no configure script!
- ".$Major.".".$Minor; ?>. I'm having problems configuring PHP to work with Apache. It says it can't find httpd.h, but it's right where I said it is!
- ".$Major.".".$Minor; ?>. When I run configure, it says that it can't find the include files or library for GD, gdbm, or some other package!
- ".$Major.".".$Minor; ?>. When it is compiling the file language-parser.tab.c, it gives me errors that say 'yytname undeclared'.
- ".$Major.".".$Minor; ?>. When I run 'make', it seems to run fine but then fails when it tries to link the final application complaining that it can't find some files.
- ".$Major.".".$Minor; ?>. When linking PHP, it complains about a number of undefined references.
- ".$Major.".".$Minor; ?>. I can't figure out how to build PHP with Apache 1.3.
- ".$Major.".".$Minor; ?>. I have followed all the steps to install the Apache module version on UNIX, and my PHP scripts show up in my browser or I am being asked to save the file.
- ".$Major.".".$Minor; ?>. It says to use: --activate-module=src/modules/php3/libphp3.a, but that file doesn't exist, so I changed it to --activate-module=src/modules/php3/libmodphp3.a and it doesn't work!? What's going on?
- ".$Major.".".$Minor; ?>. When I try to build Apache with PHP as a static module using --activate-module=src/modules/php3/libphp3.a it tells me that my compiler is not ANSI compliant.
- ".$Major.".".$Minor; ?>. When I try to build PHP using --with-apxs I get strange error messages.
- . Using PHP
- ".$Major.".".$Minor; ?>. I would like to write a generic PHP script that can handle data coming from any form. How do I know which POST method variables are available?
- ".$Major.".".$Minor; ?>. I need to convert all single-quotes (') to a backslash followed by a single-quote. How can I do this with a regular expression?
- ".$Major.".".$Minor; ?>. When I do the following, the output is printed in the wrong order, what's going on?
- ".$Major.".".$Minor; ?>. Hey, what happened to my newlines?
- ".$Major.".".$Minor; ?>. I need to access information in the request header directly. How can I do this?
- ".$Major.".".$Minor; ?>. When I try to use authentication with IIS I get 'No Input file specified'.
- ".$Major.".".$Minor; ?>. I've followed all the instructions, but still can't get PHP and IIS to work together!
- ".$Major.".".$Minor; ?>. My PHP script works on IE and Lynx, but on Netscape some of my output is missing. When I do a "View Source" I see the content in IE but not in Netscape.
- ".$Major.".".$Minor; ?>. How am I supposed to mix XML and PHP? It complains about my <?xml> tags!
- ".$Major.".".$Minor; ?>. How can I use PHP with FrontPage or Dreamweaver or some other HTML editor that insists on moving my code around?
- ".$Major.".".$Minor; ?>. Where can I find a complete list of pre-set variables available to me, and why are these not documented in the PHP documentation?
- ".$Major.".".$Minor; ?>. Why do I get an error that looks something like this: "Warning: 0 is not a MySQL result index in file on line 8"?
- ".$Major.".".$Minor; ?>. I'm trying to use an <INPUT TYPE="image"> tag, but the $foo.x and $foo.y variables aren't available. Where are they?
- . PHP and HTML
- . PHP and other languages
- . Common Problems
- ".$Major.".".$Minor; ?>. I installed PHP, but every time I load a document, I get the message 'Document Contains No Data'! What's going on here?
- ".$Major.".".$Minor; ?>. I'm trying to access one of the standard CGI variables (such as $DOCUMENT_ROOT or $HTTP_REFERER) in a user-defined function, and it can't seem to find it. What's wrong?
- ".$Major.".".$Minor; ?>. I patched Apache with the FrontPage extensions patch, and suddenly PHP stopped working. Is PHP incompatible with the Apache FrontPage extensions?
- ".$Major.".".$Minor; ?>. Why do I get 'Fatal error: Call to undefined function: some_function() in /myscript.php3 on line X'? Most often MySQL functions?
- ".$Major.".".$Minor; ?>. I think I found a bug! Who should I tell?
- . Migrating from PHP3 to PHP4
- . Migrating from PHP2 to PHP3
. General Information
- ".$Major.".".$Minor; ?>. What is PHP?
-
From the manual:
A nice introduction to PHP by Stig Sæther Bakken can be found here on the Zend website.PHP Version 3.0 is an HTML-embedded scripting language. Much of its syntax is borrowed from C, Java and Perl with a couple of unique PHP-specific features thrown in. The goal of the language is to allow web developers to write dynamically generated pages quickly.
- ".$Major.".".$Minor; ?>. What is the relation between the versions?
-
PHP/FI 2.0 is an early and no longer supported version of PHP. PHP 3 is the successor to PHP/FI 2.0 and is a lot nicer.
PHP 4 is the latest generation of PHP, which uses the Zend engine under the hood.
- ".$Major.".".$Minor; ?>. Can I run several versions of PHP at the same time?
-
Under *nix/*BSD:
PHP3 and PHP4 can both be run as Modules under Apache. The directions are in the INSTALL file in the tarball, the "nut" of that is to use --with-versioning and --with-apxs when compiling Apache.For even greater flexibility, one can run as many versions of PHP2/3/4 as stand-alone binaries (aka CGI version) as desired by choosing unique extensions (.php2, .php3, .php4 for example) for filenames, and editing httpd.conf to reflect these choices. Something like:
AddType application/httpd-script-php2 php2
Action application/httpd-script-php2 /full/path/to/php2/binary
AddType application/httpd-script-php3 php3
Action application/httpd-script-php3 /full/path/to/php3/binary
AddType application/httpd-script-php4 php4
Action application/httpd-script-php4 /full/path/to/php4/binary
In essence, Apache is being told about three external software packages that conform to CGI specs, and none of the three are really related to each other as far as Apache is concerned.
Once can even utilize this methodology to debug version-related problems, by simply choosing unique extensions for each PHP version of interest. For example, PHP3.0.5, PHP3.0.7, and PHP3.0.12 could all be run on the same server with:
AddType application/httpd-script-php305 php305
Action application/httpd-script-php305 /full/path/to/php305/binary
AddType application/httpd-script-php307 php307
Action application/httpd-script-php307 /full/path/to/php307/binary
AddType application/httpd-script-php3012 php3012
Action application/httpd-script-php3012 /full/path/to/php3012/binary
The anatomy of AddType/Application is this:
AddType uniqueID fileextension
Action uniqueID pathtoCGIbinary
It is customary to use uniqueID of a form that clearly identifies the software involved: This is particularly critical for entries that have no Action, because they are handled by client-side plug-ins. For this usage, it really only matters that your uniqueID does not conflict with any other Type-Handler, and that you can keep it all organized.
Under Windows32:
Trying to run two different versions of php on the same system in Apache you will need PHP compiled as a CGI.Apache httpd.conf settings
ScriptAlias: This refers to the actual location of your php3 or 4 directories that contain the php executable
ScriptAlias /php3/ "C:/web/php3/"
ScriptAlias /php4/ "C:/web/php4/"AddType: In these settings *.php, *.inc and *.htm is handled by PHP3 and *.php4 is handled by PHP4
AddType application/x-httpd-php3 .php .inc .htm
AddType application/x-httpd-php4 .php4
Action application/x-httpd-php3 "/php3/php.exe"
Action application/x-httpd-php4 "/php4/php.exe"
If you are using Personal webserver (or even IIS ) you will have to hack the php_iis_reg.inf supplied with PHP3 (or 4) to do the correct settings:
If you were on windows 95 modify the [INFTool.Add.Reg.95] section (if you are using NT you will need to make similiar changes).[INFTool.Add.Reg.95]
HKLM,"System\CurrentControlSet\Services\W3Svc\Parameters\Script Map",".php",0,"c:\web\php3\php.exe %s %s"
HKLM,"System\CurrentControlSet\Services\W3Svc\Parameters\Script Map",".htm",0,"c:\web\php3\php.exe %s %s"
HKLM,"System\CurrentControlSet\Services\W3Svc\Parameters\Script Map",".inc",0,"c:\web\php3\php.exe %s %s"
HKLM,"System\CurrentControlSet\Services\W3Svc\Parameters\Script Map",".php4",0,"c:\web\php4\php.exe %s %s"
HKCR,".php","",0,"phpfile"
HKCR,".htm","",0,"phpfile"
HKCR,".inc","",0,"phpfile"
HKCR,".php4","",0,"php4file"
HKCR,"phpfile","",0,"PHP Script"
HKCR,"php4file","",0,"PHP Script"
HKCR,"phpfile","EditFlags",1,00,00,01,00
HKCR,"phpfile\Shell\open","EditFlags",1,01,00,00,00
HKCR,"phpfile\Shell\open\command","",0,"c:\web\php3\php.exe %1"
HKCR,"php4file","EditFlags",1,00,00,01,00
HKCR,"php4file\Shell\open","EditFlags",1,01,00,00,00
HKCR,"php4file\Shell\open\command","",0,"c:\web\php4\php.exe %1"
Both of these examples should give you .php, .inc and .htm run by PHP3 and .php4 run by PHP4.
Be aware that you will have separate php3.ini and php.ini (for php4) files so they need to be similiar and maintained separately. Be aware they are not the same! Do not copy php3.ini over php.ini!
- ".$Major.".".$Minor; ?>. What are the differences between PHP 3 and PHP 4?
-
There are a couple of articles written on this by the authors of PHP4. Here's a list of some of the more important new features:
- Extended API module
- Generalized build process under UNIX
- Generic web server interface that also supports multi-threaded web servers
- Improved syntax highlighter
- Native HTTP session support
- Output buffering support
- More powerful configuration system
- Reference counting
- ".$Major.".".$Minor; ?>. How did you do those pop-out windows for the Search and Mirror buttons on the PHP site (www.php.net)?
-
Our site designer, Colin Viebrock (cmv <email protected>), says:
Those fancy pop-out layers are done with Dynamic HTML (DHTML), Cascading Style Sheets (CSS) and Javascript (version 1.2).
There are plenty of references on the web about DHTML and CSS, including:
- CSS Level 1 Spec: www.w3.org/TR/REC-CSS1
- Macromedia's DHTML Zone: www.dhtmlzone.com/index.html
- Webreference's DHTML Lab: www.webreference.com/dhtml/
- Guide to Cascading Style Sheets: www.htmlhelp.com/reference/css/
- Dynamic Duo - Cross-Browser DHTML: www.dansteinman.com/dynduo/
- Netscape's Guide to JS 1.2: developer.netscape.com/docs/manuals/communicator/jsguide/js1_2.htm
But your best source of information is to view the source code to the pages on the PHP site. To see the actual DHTML/Javascript code, use your browser's "View Source" function. To see how this code was generated dynamically using PHP, click on the "Source" button in the upper-right corner of any PHP page. You will probably also want to view the source of the "shared.inc" file - there is a link to it at the bottom of every source page.
. PHP mailing lists
- ".$Major.".".$Minor; ?>. Is there a PHP mailing list?
-
Of course! To subscribe, send mail to
php3-subscribe <email protected>. You don't need to include anything special in the subject or body of the message.To unsubscribe, send mail to
php3-unsubscribe <email protected>. - ".$Major.".".$Minor; ?>. Help! I can't seem to subscribe to the mailing list!
- Help! I can't seem to unsubscribe from the mailing list!
-
If you have problems subscribing to or unsubscribing from the
PHP mailng list, it may be because the mailing list software
can't figure out the correct mailing address to use. If
your email address was
joeblow <email protected>, you can send your subscription request tophp3-subscribe-joeblow=example.com <email protected>, or your unsubscription request tophp3-unsubscribe-joeblow=example.com <email protected>. - ".$Major.".".$Minor; ?>. Is there an archive of the mailing list anywhere?
-
Yes, you will find a list of archive sites on the Support
page.
- ".$Major.".".$Minor; ?>. What can I ask the mailing list?
-
Since PHP is growing more and more popular by the day the traffic has increased on the PHP mailing list and as of now the list gets about 150 to 200 posts a day. Because of this it
is in everyones interest that you use the list as a last resort when you have looked everywhere else.
Before you post to the list please have a look in this FAQ and the manual to see if you can find the help there. If there is nothing to be found there try out the mailing list archives (see above). If you're having problem with installing or configuring PHP please read through all included documentation and README's. If you still can't find any information that helps you out you're more than welcome to use the mailing list.
- ".$Major.".".$Minor; ?>. What information should I include when posting to the mailing list?
-
Posts like "I can't get PHP up and running! Help me! What is wrong?" are of absolutetly no use to anyone. If you're having problems getting PHP up and running you must include
what operating system your running on, what version of PHP you're trying to set up, how you got it (pre-compiled, CVS, RPMs and so on), what you have done so far, where you got
stuck and the exact error message.
This goes for any other problem as well. You have to include information on what you have done, where you got stuck, what you're trying to do and, if applicable, exact error messages. If you're having problems with your source code you need to include the part of the code that isn't working. Do not include more code than necessary though! It makes the post hard to read and a lot of people might just skip it all together because of this. If you're unsure about how much information to include in the mail it's better that you include to much than to little.
Another important thing to remember is to summarize your problem on the subject line. A subject like "HELP MEEEE!!!" or "What is the problem here?" will be ignored by the majority of the readers. - ".$Major.".".$Minor; ?>. When should I reply to the list?
- If you feel that your answer is of importance to the rest of the list you should reply to both the list and the originator of the post you're replying to. If the information the poster asks for is very specific you should only reply to him/her. If a user asks an off-topic (OT) question, like "What Linux to use?", or if the question isn't related to PHP (JavaScript, Perl, MySQL, and so on) you should reply directly to him/her as well. This is also because of the fact that the list is busy enough as it is.
. Obtaining PHP
- ".$Major.".".$Minor; ?>. Where can I obtain PHP?
-
You can download PHP from any of the members of the
PHP network of sites. These can be found at http://www.php.net/.
You can also use anonymous CVS to get the absolute latest
version of the source. For more information, go to http://cvs.php.net.
- ".$Major.".".$Minor; ?>. Are pre-compiled binary versions available?
-
Yes, although they are not always up to date. The Windows binary is
generally current, but the Unix binaries lag behind and are only available
for certain platforms. All download are available in the
Downloads section.
- ".$Major.".".$Minor; ?>. Where can I get libraries needed to compile some of the optional PHP extensions?
-
Note: Those marked with * are not thread-safe libraries, and
should not be used with PHP as a server module in the multi-threaded
Windows web servers (IIS, Netscape). This does not matter in Unix
environments, yet.
- LDAP (unix): ftp://ftp.openldap.org/pub/openldap/openldap-stable.tgz
- LDAP* (unix): ftp://terminator.rs.itd.umich.edu/ldap/ldap-3.3.tar.Z
- LDAP (unix/win): Netscape Directory (LDAP) SDK 1.1 There is also a free LDAP server at: ftp://ftp.critical-angle.com/pub/cai/slapd/.
- Berkeley DB2 (Unix/Win): http://www.sleepycat.com/
- SNMP* (Unix): http://www.ece.ucdavis.edu/ucd-snmp/ (Note: PHP uses the native SNMP interface in Windows.)
- GD* (Unix/Win): http://www.boutell.com/gd/#buildgd
- mSQL* (Unix): http://www.hughes.com.au/
- mSQL* (Win) : MSQL PC Home Page
- MySQL (Unix): http://www.mysql.com/
- IMAP* (Win/Unix): ftp://ftp.cac.washington.edu/imap/old/imap-4.5.tar.Z
- Sybase-CT* (Linux, libc5): Available locally
- FreeType (libttf): http://www.freetype.org/
- ZLib (Unix/Win32): http://www.cdrom.com/pub/infozip/zlib/
- expat XML parser (Unix/Win32): http://www.jclark.com/xml/expat.html
- PDFLib: http://www.pdflib.com
- mcrypt: ftp://argeas.cs-net.gr/pub/unix/mcrypt/
- mhash: http://sasweb.de/mhash/
- t1lib: http://www.neuroinformatik.ruhr-uni-bochum.de/ini/PEOPLE/rmz/t1lib/t1lib.html
- dmalloc: http://www.dmalloc.com/
- aspell: http://download.sourceforge.net/aspell/aspell-.29.1.tar.gz
- Readline: ftp://prep.ai.mit.edu/pub/gnu/readline/
- ".$Major.".".$Minor; ?>. How do I get these libraries to work?
-
You will need to follow instructions provided with the library. Some of
these libraries are detected automatically when you run the 'configure'
script of PHP (such as the GD library), and others you will have to
enable using '--with-EXTENSION' options to 'configure'. Run 'configure
--help' for a listing of these.
- ".$Major.".".$Minor; ?>. I got the latest version of the PHP source code from the CVS repository on my Windows 95/NT machine, what do I need to compile it?
-
First, you will need Microsoft Visual C++ v6 (v5 may do
it also, but we do it with v6), and you will need to download the
support files. You will need to unzip this file (which
has subdirectories, so make sure your unzip program keeps them)
into the win32 subdirectory of the source distribution.
- ".$Major.".".$Minor; ?>. Where do I find the Browser Capabilities File?
-
You can find a browscap.ini file at http://www.cyscape.com/asp/browscap/.
. Installation
To install PHP, follow the instructions in the INSTALL file located in the distribution. Windows 95 and NT users should also read the README.WIN32 file. There are also some helpful hints for Windows users here.
If you are trying to install PHP for use with Netscape's web server on Unix see: http://www.webgenx.com/php/phpnes.php3
- ".$Major.".".$Minor; ?>. Where should my php3.ini file be located?
-
By default on UNIX it should be in /usr/local/lib. Most people will want
to change this at compile-time with the --with-config-file-path flag. You would, for
example, set it to something like:
--with-config-file-path=/etc
And then you would copy php3.ini-dist from the distribution to /etc/php3.ini and edit it to make any local changes you want. - ".$Major.".".$Minor; ?>. I installed PHP using RPMS, but Apache isn't processing the PHP pages! What's going on here?
-
- Assuming you installed Apache PHP completely with RPMS, you need to uncomment or add some or all of the following lines in your http.conf file:
# Extra Modules
AddModule mod_php.c
AddModule mod_php3.c
AddModule mod_perl.c
# Extra Modules
LoadModule php_module modules/mod_php.so
LoadModule php3_module modules/libphp3.so
LoadModule perl_module modules/libperl.so
- And add:
AddType application/x-httpd-php3 .php3
To the global properties, or to the properties of the VirtualDomain you want to have PHP support added to.
- Assuming you installed Apache PHP completely with RPMS, you need to uncomment or add some or all of the following lines in your http.conf file:
- ".$Major.".".$Minor; ?>. I installed PHP using RPMS, but it doesn't compile with the database support I need! What's going on here?
-
Due to the way PHP is currently built, it is not easy to build a complete flexible PHP RPM. This
issue will be addressed in PHP4. For PHP, we currently suggest you use the mechanism described
in the INSTALL.REDHAT file in the PHP distribution. If you insist on using an RPM version of PHP,
read on...
Currently the RPM packagers are setting up the RPMS to install without database support to simplify installations AND because RPMS use /usr/ instead of the standard /usr/local/ directory for files. You need to tell the RPM spec file which databases to support and the location of the top-level of your database server.
This example will explain the process of adding support for the popular MySQL database server, using the mod installation for Apache.
Of course all of this information can be adjusted for any database server that PHP supports. I will assume you installed MySQL and Apache completely with RPMS for this example as well.- First remove mod_php3
rpm -e mod_php3
- Then get the source rpm and INSTALL it, NOT --rebuild
rpm -Uvh mod_php3-3.0.5-2.src.rpm
- Then edit the /usr/src/redhat/SPECS/mod_php3.spec file
In the %build section add the database support you want, and the path.
For MySQL you would add--with-mysql=/usr \
The %build section will look something like this:
./configure --prefix=/usr \
--with-apxs=/usr/sbin/apxs \
--with-config-file-path=/usr/lib \
--enable-debug=no \
--enable-safe-mode \
--with-exec-dir=/usr/bin \
--with-mysql=/usr \
--with-system-regex
- Once this modification is made then build the binary rpm as follows:
rpm -bb /usr/src/redhat/SPECS/mod_php3.spec
- Then install the rpm
rpm -ivh /usr/src/redhat/RPMS/i386/mod_php3-3.0.5-2.i386.rpm
- First remove mod_php3
. Build Problems
- ".$Major.".".$Minor; ?>. I got the latest version of PHP using the anonymous CVS service, but there's no configure script!
-
You have to have the GNU autoconf package installed so you can
generate the configure script from configure.in. Just run
make -f build.mkin the top-level directory after getting the sources from the CVS server. (Also, unless you run configure with the--enable-maintainer-modeoption, the configure script will not automatically get rebuilt when the configure.in file is updated, so you should make sure to do that manually when you notice configure.in has changed. One symptom of this is finding things like <email protected>@ in your Makefile after configure or config.status is run.) - ".$Major.".".$Minor; ?>. I'm having problems configuring PHP to work with Apache. It says it can't find httpd.h, but it's right where I said it is!
-
You need to tell the configure/setup script the location of the
top-level of your Apache source tree. This means that
you want to specify '
--with-apache=/path/to/apache' and not '--with-apache=/path/to/apache/src'. - ".$Major.".".$Minor; ?>. When I run configure, it says that it can't find the include files or library for GD, gdbm, or some other package!
-
You can make the configure script looks for header files and libraries
in non-standard locations by specifying additional flags to pass to
the C preprocessor and linker, such as:
CPPFLAGS=-I/path/to/include LDFLAGS=-L/path/to/library ./configureIf you're using a csh-variant for your login shell (why?), it would be:env CPPFLAGS=-I/path/to/include LDFLAGS=-L/path/to/library ./configure - ".$Major.".".$Minor; ?>. When it is compiling the file language-parser.tab.c, it gives me errors that say 'yytname undeclared'.
-
You need to update your version of Bison. You can find the latest version
at ftp://prep.ai.mit.edu/pub/gnu/.
- ".$Major.".".$Minor; ?>. When I run 'make', it seems to run fine but then fails when it tries to link the final application complaining that it can't find some files.
-
Some old versions of make that don't correctly put the compiled
versions of the files in the functions directory into that same
directory. Try running "
cp *.o functions" and then re-running 'make' to see if that helps. If it does, you should really upgrade to a recent version of GNU make. - ".$Major.".".$Minor; ?>. When linking PHP, it complains about a number of undefined references.
-
Take a look at the link line and make sure that all of the appropriate
libraries are being included at the end. Common ones that you might have
missed are '-ldl' and any libraries required for any database support
you included.
If you're linking with Apache 1.2.x, did you remember to add the appropriate information to the EXTRA_LIBS line of the Configuration file and re-rerun Apache's Configure script? See the INSTALL file that comes with the distribution for more information.
Some people have also reported that they had to add '-ldl' immediately following 'libphp3.a' when linking with Apache.
- ".$Major.".".$Minor; ?>. I can't figure out how to build PHP with Apache 1.3.
-
This is actually quite easy. Follow these steps carefully:
- Grab the latest Apache 1.3 distribution from www.apache.org.
- Ungzip and untar it somewhere, for example /usr/local/src/apache-1.3.
- Compile PHP by first running ./configure --with-apache=/<path>/apache-1.3 (substitute <path> for the actual path to your apache-1.3 directory.
- Type 'make' followed by 'make install' to build PHP and copy the necessary files to the Apache distribution tree.
- Change directories into to your /<path>/apache-1.3/src directory and edit the Configuration file. At the end of the file, add: AddModule modules/php3/libphp3.a.
- Type: './Configure' followed by 'make'.
- You should now have a PHP-enabled httpd binary!
- ".$Major.".".$Minor; ?>. I have followed all the steps to install the Apache module version on UNIX, and my PHP scripts show up in my browser or I am being asked to save the file. Help!
-
This means that the PHP module is not getting invoked for some reason. Three things to check before asking for further help:
- Make sure that the httpd binary you are running is the actual new httpd binary you just built. To do this,
try running: /path/to/binary/httpd -l
If you don't see mod_php3.c listed then you are not running the right binary. Find and install the correct binary. - Make sure you have added the correct Mime Type to one of your Apache .conf files. It should be: AddType application/x-httpd-php3 .php3
Also make sure that this AddType line is not hidden away inside a <Virtualhost> or <Directory> block which would prevent it from applying to the location of your test script. - Finally, the default location of the Apache configuration files changed between Apache 1.2 and Apache 1.3. You should check to make sure that the configuration file you are adding the AddType line to is actually being read. You can put an obvious syntax error into your httpd.conf file or some other obvious change that will tell you if the file is being read correctly.
- Make sure that the httpd binary you are running is the actual new httpd binary you just built. To do this,
try running: /path/to/binary/httpd -l
- ".$Major.".".$Minor; ?>. It says to use: --activate-module=src/modules/php3/libphp3.a, but that file doesn't exist, so I changed it to --activate-module=src/modules/php3/libmodphp3.a and it doesn't work!? What's going on?
-
Well, you decided to try to outsmart the people who wrote those nice step-by-step instructions for you and you
have now discovered that these people cannot be outsmarted. The libphp3.a file is not supposed to
exist. The Apache build process will create it.
- ".$Major.".".$Minor; ?>. When I try to build Apache with PHP as a static module using --activate-module=src/modules/php3/libphp3.a it tells me that my compiler is not ANSI compliant.
- This is a misleading error message and has been fixed in Apache-1.3.10 and later versions. You should upgrade to the latest version of Apache.
- ".$Major.".".$Minor; ?>. When I try to build PHP using --with-apxs I get strange error messages
-
There are two things to check here. First, for some reason when Apache builds the apxs Perl
script, it sometimes ends up getting built without the proper compiler and flags variables.
Edit your apxs (sometimes found in /usr/local/apache/bin/apxs or /usr/sbin/apxs) and check
for these lines:
my $CFG_CFLAGS_SHLIB = ' '; # substituted via Makefile.tmpl my $CFG_LD_SHLIB = ' '; # substituted via Makefile.tmpl my $CFG_LDFLAGS_SHLIB = ' '; # substituted via Makefile.tmpl
If this is what you see, you have found your problem. Change these lines to say:my $CFG_CFLAGS_SHLIB = q(-fpic -DSHARED_MODULE); # substituted via Makefile.tmpl my $CFG_LD_SHLIB = q(gcc); # substituted via Makefile.tmpl my $CFG_LDFLAGS_SHLIB = q(-shared); # substituted via Makefile.tmpl
The second possible problem should only be an issue on RedHat-6.1. The apxs script RedHat ships is broken. Look for this line:my $CFG_LIBEXECDIR = 'modules'; # substituted via APACI install
If you see the above line, change it to this:my $CFG_LIBEXECDIR = '/usr/lib/apache'; # substituted via APACI install
. Using PHP
- ".$Major.".".$Minor; ?>. I would like to write a generic PHP script that can handle data coming from any form. How do I know which POST method variables are available?
-
Make sure that the track_vars feature is enabled in your php3.ini file. If you
compiled PHP with "--enable-track-vars" it will be on by default.
Alternatively you can enable it at run-time on a per-script basis by putting
<?php_track_vars?> at the top of your file.
When track_vars is on, it creates three associative arrays. $HTTP_GET_VARS, $HTTP_POST_VARS
and $HTTP_COOKIE_VARS. So, to write a generic script to handle POST
method variables you would need something similar to the following:
while (list($var, $value) = each($HTTP_POST_VARS)) { echo "$var = $value<br>\n"; } - ".$Major.".".$Minor; ?>. I need to convert all single-quotes (') to a backslash followed by a single-quote. How can I do this with a regular expression?
-
First off, take a look at the addslashes() function. It will do
exactly what you want. You should also have a look at the magic_quotes_gpc directive in your php3.ini
file.
The ereg_replace magic you're looking for, however, is simply:
$escaped = ereg_replace("'", "\\'", $input); -
".$Major.".".$Minor; ?>. When I do the following, the output is printed in the wrong order:
function myfunc($argument) { echo $argument + 10; } $variable = 10; echo "myfunc($variable) = " . myfunc($variable); -
What's going on?
To be able to use the results of your function in an expression (such as concatenating it with other strings in the example above), you need to return the value, not echo it. -
".$Major.".".$Minor; ?>. Hey, what happened to my newlines in:
1 <?echo $result[1];?> 2 <?echo $result[2];?>
-
In PHP, the ending for a block of code is either "?>" or
"?>\n" (where \n means a newline). This means that you need to
insert an extra newline after each block of PHP code in the above
example.
Why does PHP do this? Because when formatting normal HTML, this usually makes your life easier because you don't want that newline, but you'd have to create extremely long lines or otherwise make the raw page source unreadable to achieve that effect.
- ".$Major.".".$Minor; ?>. I need to access information in the request header directly. How can I do this?
-
The getallheaders() function will do this if you are running PHP as a
module. So, the following bit of code will show you all the request
headers:
$headers = getallheaders(); for(reset($headers); $key = key($headers); next($headers)) { echo "headers[$key] = ".$headers[$key]."<br>\n"; } - ".$Major.".".$Minor; ?>. When I try to use authentication with IIS I get 'No Input file specified'
-
The security model of IIS is at fault here. This is a problem
common to all CGI programs running under IIS. A workaround is
to create a plain HTML file (not parsed by php) as the entry page
into an authenticated directory. Then use a META tag to redirect
to the PHP page, or have a link to the PHP page. PHP will
then recognize the authentication correctly. When the ISAPI
module is ready, this will no longer be a problem. This should
not effect other NT web servers. For more information, see: http://support.microsoft.com/support/kb/articles/q160/4/22.asp.
- ".$Major.".".$Minor; ?>. I've followed all the instructions, but still can't get PHP and IIS to work together!
-
Make sure any user who needs to run a PHP script has the rights
to run php.exe! IIS uses an anonymous user which is added at the
time IIS is installed. This user needs rights to php.exe. Also,
any authenticated user will also need rights to execute php.exe. And
for IIS4 you need to tell it that PHP is a script engine.
- ".$Major.".".$Minor; ?>. My PHP script works on IE and Lynx, but on Netscape some of my output is missing. When I do a "View Source" I see the content in IE but not in Netscape. Even when I telnet to port 80 directly the correct content shows up. How can this be? PHP is server-side and my browser can't possibly know that the content it is seeing is generated by PHP, so what is going on?
-
The answer is that both IE and Lynx ignore any NULs
(\0) in the HTML stream. Netscape does not. The best way to check for this is to compile
the command-line version of PHP (also known as the CGI version) and run your script from the
command line and pipe it through 'od -c' and look for any \0 characters. (If you are on
Windows you need to find an editor or some other program that lets you look at binary files)
When Netscape sees a NUL in a file it will typically not output anything else on that line
whereas both IE and Lynx will. If this issue has bitten you, congratulations! You are not
alone.
- ".$Major.".".$Minor; ?>. How am I supposed to mix XML and PHP? It complains about my <?xml> tags!
-
You need to turn off the short tags by setting short_tags to 0 in your
php3.ini file, or by using the php3_short_tags Apache directive. (You
could even use a <File> section to do this selectively.) You can
also disable and re-enable the short tags in your script using the
short_tags() function.
- ".$Major.".".$Minor; ?>. How can I use PHP with FrontPage or Dreamweaver or some other HTML editor that insists on moving my code around?
-
One of the easiest things to do is to enable using ASP tags in your
PHP code. This allows you to use the ASP-style <% and %> code
delimiters. Most of the popular HTML editors handle those more
intelligently (for now). To enable the ASP-style tags, you need
to set the asp_tags php3.ini variable, or use the php3_asp_tags
Apache directive.
- ".$Major.".".$Minor; ?>. Where can I find a complete list of pre-set variables available to me, and why are these not documented in the PHP documentation?
-
The best way is to stick a <?phpinfo()?> tag on a page and load it up. This will
show you all sorts of information about your PHP setup, including a list of both
environment variables and also special variables set by your web server. This list
can't really be documented in the PHP documentation because it will change from one
server to another.
-
".$Major.".".$Minor; ?>. Why do I always get an error that looks something like this:
Warning: 0 is not a MySQL result index in file on line 8
What am I doing wrong? -
You are trying to use a result identifier that is 0. The 0 indicates that your query failed
for some reason. You need to check for errors after submitting a query and before you
attempt to use the returned result identifier. The proper way to do this is with code similar
to the following:
$result = mysql_query("select * from tables_priv"); if(!$result) { echo mysql_error(); exit; }or:$result = mysql_query("select * from tables_priv") or die("Bad query: ".mysql_error()); - ".$Major.".".$Minor; ?>. I'm trying to use an <INPUT TYPE="image"> tag, but the $foo.x and $foo.y variables aren't available. Where are they?
-
When submitting a form, it is possible to use an image instead of the standard submit button
with a tag like:
<INPUT TYPE="image" SRC="image.gif" NAME="foo">
When the user clicks somewhere on the image, the accompanying form will be transmitted to the server with two additional variables: foo.x and foo.y.Because $foo.x and $foo.y are invalid variable names in PHP, they are automagically converted to $foo_x and $foo_y. That is, the periods are replaced with underscores.
. PHP and HTML
- ".$Major.".".$Minor; ?>. How do I create an array in a HTML <FORM>?
-
To get your <FORM> result sent as an array to your PHP script you name the <INPUT>, <SELECT> or <TEXTAREA> elements like this:
<INPUT NAME="MyArray[]"> <INPUT NAME="MyArray[]"> <INPUT NAME="MyArray[]"> <INPUT NAME="MyArray[]">
Notice the square brackets after the variable name, that's what makes it an array. You can group the elements into different arrays by assigning the same name to different elements:<INPUT NAME="MyArray[]"> <INPUT NAME="MyArray[]"> <INPUT NAME="MyOtherArray[]"> <INPUT NAME="MyOtherArray[]">
This produces two arrays, MyArray and MyOtherArray, that gets sent to the PHP script.You can use indices with arrays, both numerical and alphanumerical. If you don't the array gets filled in the order the elements appear in the form. For functions you can use to process these arrays once you get them into your scripts, please see the Arrays section in the manual.
. PHP and other languages
- ".$Major.".".$Minor; ?>. PHP vs. ASP?
- ASP is not really a language in itself, it's an acronym for Active Server Pages, the actual language used to program ASP with is a script version of Visual Basic. The biggest drawback of ASP is that it's a proprietary system that is natively used only on Microsofts Internet Information Server (IIS). This limits it's availability to Win32 based servers. There are a couple of projects in the works that allows ASP to run in other environments and webservers; InstantASP from Halcyon (commercial), Chili!Soft ASP from Chili!Soft (commercial) and OpenASP from ActiveScripting.org (free). ASP is said to be a slower and more cumbersome language than PHP, less stable as well. Some of the pros of ASP is that since it uses VBScript it's relatively easy to pick up the language if you're used to program Visual Basic. ASP support is also enabled by default in the IIS server making it easy to get up and running.
- ".$Major.".".$Minor; ?>. Is there an ASP to PHP converter?
- Yes, asp2php is the one most often referred to.
- ".$Major.".".$Minor; ?>. PHP vs. Cold Fusion?
-
PHP is commonly said to be faster and more efficient for complex programming tasks and trying out new ideas. PHP is generally referred to as more stable and less
resource intensive as well. Cold Fusion has better error handling, database abstraction and date parsing although database abstraction is being adressed in
PHP4. Another thing that is listed as one of Cold Fusions strengths is it's excellent search engine but it has been mentioned that a search engine is not something
that should be included in a web scripting language. PHP runs on almost every platform there is while Cold Fusion is only available on Win32, Solaris, Linux and HP/UX.
Cold Fusion has a better IDE and is generally easier to get started with, PHP initially requires more programming knowledge.
A great summary by Michael J Sheldon on this topic has been posted to the PHP mailing list. A copy can be found here.
- ".$Major.".".$Minor; ?>. PHP vs. Perl?
- The biggest advantage of PHP over Perl is that PHP was designed for scripting for the web where Perl was designed to do a lot more and can because of this get very complicated. The flexibility / complexity of Perl makes it easier to write code that another author / coder has a hard time reading. PHP has a less confusing and stricter format without losing flexibility. PHP is easier to integrate into existing HTML than Perl. PHP has pretty much all the 'good' functionality of Perl; constructs, syntax and so on, without making it as complicated as Perl can be. Perl is a very tried and true language, it's been around since the late eighties, but PHP is maturing very quickly.
. Common Problems
- ".$Major.".".$Minor; ?>. I installed PHP, but every time I load a document, I get the message 'Document Contains No Data'! What's going on here?
-
This probably means that PHP is having some sort of problem
and is core-dumping. Look in your server error log to see if
this is the case, and then try to reproduce the problem with
a small test case. If you know how to use 'gdb', it is very
helpful when you can provide a backtrace with your bug report
to help the developers pinpoint the problem. If you are using
PHP as an Apache module try something like:
- Stop your httpd processes
- gdb httpd
- > run -X -f /path/to/httpd.conf
- Then fetch the URL causing the problem with your browser
- If you are getting a core dump, gdb should inform you of this now
- type: bt
- Send the resulting backtrace to php-dev <email protected>
If your script uses the regular expression functions (
ereg()and friends), you should make sure that you compiled PHP and Apache with the same regular expression package. (This should happen automatically with PHP and Apache 1.3.x) - ".$Major.".".$Minor; ?>. I'm trying to access one of the standard CGI variables (such as $DOCUMENT_ROOT or $HTTP_REFERER) in a user-defined function, and it can't seem to find it. What's wrong?
-
Environment variables are now normal global variables, so you must
either declare them as global variables in your function (by using
"
global $DOCUMENT_ROOT;", for example) or by using the global variable array (ie, "$GLOBALS["DOCUMENT_ROOT"]". - ".$Major.".".$Minor; ?>. I patched Apache with the FrontPage extensions patch, and suddenly PHP stopped working. Is PHP incompatible with the Apache FrontPage extensions?
-
No, PHP works fine with the FrontPage extensions.
The problem is that the FrontPage patch modifies several Apache structures,
that PHP relies on.
Recompiling PHP (using 'make clean ; make') after the FP patch is applied
would solve the problem.
- ".$Major.".".$Minor; ?>. Why do I get 'Fatal error: Call to undefined function: some_function() in /myscript.php3 on line X'? Most often MySQL functions?
-
What PHP is complaining about is that it can't find the function you're trying to use, be it a 'built-in' function in PHP or a user-defined function.
When it comes to MySQL it is because you haven't enabled MySQL support, please see the install directions for more information on this. This most likely applies to every other
'built-in' function that you're trying to access as well, the support might not be included in the version of PHP that you are running. If you are sure that the support is
there you should check your spelling.
- ".$Major.".".$Minor; ?>. I think I found a bug! Who should I tell?
-
You should go to the PHP Bug Database and make sure the bug
isn't a known bug. If you don't see it in the database, use
the reporting form to report the bug. It is important to use
the bug database instead of just sending an email to one of the
mailing lists because the bug will have a tracking number assigned
and it will then be possible for you to go back later and check
on the status of the bug. The bug database can be found at http://bugs.php.net.
. Migrating from PHP3 to PHP4
- ".$Major.".".$Minor; ?>. General information
- PHP4 was designed to be as compatible with earlier versions of PHP as possible and very little functionality was broken in the process. If you're really unsure about compatibility you should install PHP 4 in a test environment and run your scripts there.
- ".$Major.".".$Minor; ?>. Incompatible functions
- Since PHP 4 is basically a rewrite of the entire PHP engine there was very few functions that were altered and only then some of the more exotic ones.
. Migrating from PHP2 to PHP3
- ".$Major.".".$Minor; ?>. General information
- PHP/FI 2.0 is no longer supported. Please see the manual for information about migration.
Credits
This FAQ was originally written by Jim Winstead. It is currently maintained by the PHP Development Team.
$Id: FAQ_1.3.1.php3,v 1.3.1 2000/05/29 14:00 Martin Edelius Exp $

