Theory 
NSW Schools
Maths
Science
Documentation
Efficiency
Media
Databases
E-commerce
Reporting
Reviews
Data
Simulation
Maths
Computing
Encoding
 

Printer Version of Page

Theory

php information

Simple Introduction to PHP

  • PHP code is a server side scripting language which extends the HTML makup.
  • The PHP code is between the <?php and ?> tags
  • The code may be started without using the full <?php by the shortcut instruction <?
  • The PHP parser opertates on the server and executes the instructions between the PHP opening and closing tags which may contain multiple istructions
  • PHP is generally used to send plain HTML to the browser (ie the browser does not have to do anything special like it does when interpreting JAVA Script).
  • Additional instructions must be separated by a semicolon ;
  • Most servers are setup so that files having the extension .php (instead of .htm) are read and processed by the PHP parser when a client requests them

PHP Functions

  • PHP supports many functions and interfaces with databases and the file system as well
  • Examples of simple functions with some brief instructions about them follows

php_info.php

  • <?php phpinfo(); ?>
  • This function extracts from the server specific configuration information
  • The link above points to the file php_info.php in the current subdirectory which executes the function

The source code of this (php_info.php) file is:

<html><HEAD></HEAD><body>
<?php phpinfo(); ?>
</body></html>

hello.php

  • <?php $myvar = "Hello World"; echo $myvar; ?>
  • This is a very simple example of assigning a value to a variable and then "printing" or "echoing" the variables value to the file so that it can be rendered by the browser
  • The link above points to the file hello.php in the scripts subdirectory which executes the function

The source code of this (hello.php) file is:

<html><HEAD></HEAD><body>
<?php $statement ="Hello World"; echo ("$statement"); ?>
</body></html>

helloname.php?name=Barney Rubble

  • <?php echo "$name"; ?>
  • This is a slightly more realistic example of assigning a value to a variable and then "printing" or "echoing" the variables value to the file so that it can be rendered by the browser
  • The link above points to the file helloname.php in the scripts subdirectory which executes the function

The source code of this (helloname.php) file is:

<html><HEAD></HEAD><body>
<P>Hello <?php echo "$name;" ?>
<PRE>You accessed this script using the filename:
helloname.php?name=<?php echo "$name;" ?></PRE>
<ul>
<li>Why dont you try another extension helloname.php?name=anything you like
<li>Remember blank spaces in URLs can sometimes cause problems
</ul>
</body></html>

The Date Function

  • This function can be used to insert the current server date into a file
  • There are various options or parameters which can be set which result in the date function being rendered in different formats.

today.php

Today's Date (according to this Web server) is:
<?php echo( date("l, F dS Y.") ); ?>

The source code of this (today.php) file is:

<html><HEAD></HEAD><body>
<P>Today's Date (according to this Web server) is:
<BR><?php echo( date("l, F dS Y.") ); ?>
</body></html>

Environment Variables

  • The operation of some scripts requires that information be gathered by the server concerning the configuration of the clients computer system.
  • This information is extracted in the form of Environment Variables.
  • The environment variables can be printed to the file by applying the echo function to the Environment Variables as follows

remote_info.php

  • Remote Address: <?php echo $REMOTE_ADDR; ?>
  • Remote Host: <?php echo $REMOTE_HOST; ?>
  • Remote Port: <?php echo $REMOTE_PORT; ?>
  • Remote User: <?php echo $REMOTE_USER; ?>
  • User Agent (Browser): <?php echo $HTTP_USER_AGENT; ?>

The source code of this (remote_info.php) file is:

<html><HEAD></HEAD><body>
<P>Remote Address: <?php echo $REMOTE_ADDR; ?>
<P>Remote Host: <?php echo $REMOTE_HOST; ?>
<P>Remote Port: <?php echo $REMOTE_PORT; ?>
<P>Remote User: <?php echo $REMOTE_USER; ?>
<P>User Agent (Browser): <?php echo $HTTP_USER_AGENT; ?>
</body></html>

Inline Image - Go To www.precisioninfo.com