PHP (recursive acronym for "PHP: Hypertext Preprocessor") is a widely-used Open Source general-purpose scripting language that is especially suited for Web development and can be embedded into HTML.
- Primary source: www.php.net
- Superb companion to MySQL database
- See also Server Side Includes (SSI) for other server side technology
A few examples
<?php print "<html><head><title>Hello, World! Script</title></head>\n"; print "<body>\n"; print "<p>Hello, World!</p>\n"; print "</body></html>\n"; ?>
Output from phpinfo(1).
<?php ob_start(); // start output buffer, => nothing's displayed until buffer's closed phpinfo(1); // Show just general information (1) $php_info .= ob_get_contents(); ob_end_clean(); $php_info = str_replace("</body></html>", "", $php_info); $offset = strpos($php_info, "<table"); print substr($php_info, $offset); ?>
- Environment Variables
- mail - send mail (send emails)
- Problems and Solutions
- Shell Scripts in PHP
- Testing Scripts
- Macintosh Notes
how to get client's IP address in PHP - http://www.phpbuilder.com/board/showthread.php?t=10327697
reserved variables - http://ro.php.net/manual/en/reserved.variables.php
mail - send mail (send emails)
(PHP 4, PHP 5) mail — Send mail, man page: us2.php.net/manual/en/function.mail.php
Problems and Solutions
Until further notice, pls see Perl-section for more troubleshooting in general.
php-and-ssi.php - tests
Shell Scripts in PHP
If want to create scripts for use both in web server but also maybe occasionally as scripts.
!/usr/bin/env php <?php print "<html><head><title>Printenv Script</title></head>\n"; print "<body>\n"; print "Hello, World, in PHP"; print "</body></html>\n"; ?>
1) Shebang as first line
2) (Apparently) Also must have '<?php' .. '?>' also in scripts, to work what so ever.
3) Make sure executable (e.g. chmod a+x)
Note: Difference in how works on 1&1:
With '!/usr/bin/php ' as shebang:
(uiserver):uXXX:~/comgt-com/... > ./printenv.php
With '!/usr/bin/env php ' as shebang:
(uiserver):uXXX:~/comgt-com/... > ./printenv.sh.php
- google writing shell scripts in php
- blog.digitalstruct.com/ 2007/04/24/ tips and tricks php shell scripts
Click to see how the web server handles different potential issues, details that may differ on different servers. All opens in a separate window (or tab).
|printhello.php||Hello, World! program|
|phpinfo.php||print lots of info about runtime environment|
Standard installation - that is part of standard Mac OS X 10.6 - still isn't including (e.g.) mcrypt.
(Compare what was installed 2009-09-08 on MacMini (PHP 5.2.9, Entropy release 7) and standard OS X 10.6 (PHP 5.3.0). See all saved static phpinfo() results. Note: MacMini config retrieved via http://192.168.1.4/comgt/inuse/lib/php/phpinfo.php)
Better to download and install Entropy's (which did earlier on Mac OS X 10.5).
Download (v5.3.0): http://www2.entropy.ch/download/Entropy%20PHP%205.3.0-3.pkg (53.4 MB, can take quite a while... At least half hour. Seems like Entropy has a slow server - other communications are working quite fine when downloading this in 2009-09-08 ~15:30 US Central Time).
### PHP is by default NOT enabled; to enable uncomment one line in httpd.conf and restart server:
|Default /etc/apache2/httpd.conf (== /private/etc/apache2/httpd.conf)|
... # 2008-02-27 Wed: removing preceeding '#' from line below
- <none yet>
- General: www.php.net
- Documentation: www.php.net/docs.php
- PHP Tutorial - Learn PHP: www.tizag.com/phpT
- For 10.4, older:
- 10.4: Install Apache2, PHP5, and MySQL5 http://www.macosxhints.com/article.php?story=20051214031718251