webspace hosting reseller hosting|             | blog| forum| dating| free hosting| openhost| report abuse
Internet Fax To Email - Unlimited

Unlimited Faxes, No Fees, Dedicated Phone Number

Free Website Templates

 

 

Introduction to PHP
PHP Installation
PHP Syntax
PHP Operators
PHP Conditional Statements
PHP Looping
PHP Functions
PHP More Functions
PHP Forms
PHP Cookies
PHP Include Files(SSL)
PHP The Date
PHP Database ODBC
Tutorials for PHP

PHP Functions

The real power of PHP comes from its functions.

In PHP - there are more than 700 functions available.


PHP Functions

We will only list a few useful functions in this tutorial.

A complete list of PHP functions


PHP Information

The phpinfo() function is used to output PHP information.

This function is useful for trouble shooting, providing the version of PHP, and how it is configured.

The phpinfo() function options

Name Description
INFO_GENERAL The configuration line, php.ini location, build date, Web Server, System and more
INFO_CREDITS PHP 4 credits
INFO_CONFIGURATION Local and master values for php directives
INFO_MODULES Loaded modules
INFO_ENVIRONMENT Environment variable information
INFO_VARIABLES All predefined variables from EGPCS (Environment, GET, POST, Cookie, Server)
INFO_LICENSE PHP license information
INFO_ALL Shows all of the above. This is the default value

Example

<html>
<body>
<?php
// Show all PHP information
phpinfo();
?>
<?php
// Show only the general information
phpinfo(INFO_GENERAL);
?>
</body>
</html>


PHP Server Variables

All servers hold information such as which URL the user came from, what's the user's browser, and other information. This information is stored in variables.

In PHP, the $_SERVER is a reserved variable that contains all server information. The $_SERVER is a global variable - which means that it's available in all scopes of a PHP script.

Example

The following example will output which URL the user came from, the user's browser, and the user's IP address:

<html>
<body>
<?php
echo "Referer: " . $_SERVER["HTTP_REFERER"] . "<br />";
echo "Browser: " . $_SERVER["HTTP_USER_AGENT"] . "<br />";
echo "User's IP address: " . $_SERVER["REMOTE_ADDR"];
?>
</body>
</html>


PHP Header() Function

The header() function is used to send raw HTTP headers over the HTTP protocol.

Note: This function must be called before anything is written to the page!

Example

The following example will redirect the browser to the following URL: http://www.w3schools.com/:

<?php
//Redirect browser
header("Location: http://www.w3schools.com/");
?>
<html>
<body>
......
</body>
</html>

Note: This function also takes a second parameter - an optional value of true or false to determine if the header should replace the previous header. Default is TRUE.

However, if you pass in FALSE as the second argument you can FORCE multiple headers of the same type.

Example

<?php
header("WWW-Authenticate: Negotiate");
header("WWW-Authenticate: NTLM", FALSE);
?>
<html>
<body>
......
</body>
</html>