From Redbrick Wiki
Revision as of 20:45, 28 September 2010 by Isaac702 (talk | contribs) (Remove legacy information.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This is a quick introduction to PHP, which will be expanded on (eventually).

What is PHP?

PHP Hyper-text Pre-Processor. Allows web developers to write dynamically generated pages quickly. With synergy!

PHP manual:

Basic PHP

  • cd to your ~/public_html folder on Redbrick.
cd ~/public_html

nano hello.php
  • Type this PHP code into the file
   echo "Hello World!";
  • Save and exit (CTRL + O, CTRL + X)
  • Set correct permissions for the php file (this must be done for every .php file you want to use).
chmod 700 hello.php
  • Visit to view your script's output.
  • It should display “Hello World!” in plain text within your browser.

The include() function

Without understanding much about the details of PHP, you can save yourself a great deal of time with the use of the PHP include function. The include function takes a file name and simply inserts that file's contents into the script that calls the include function. (Ref:


<a href="">Home</a> -
<a href="">About Us</a> -
<a href="">Links</a> -
<a href="">Contact Us</a>


<?php include("menu.php"); ?>

Where you inserted “include(“menu.php”);” the contents of menu.php are included into index.php at that location. When you add or remove pages from your website, you only need to update one file, menu.php, in order to display a link on every page in your website that includes menu.php.


Like any decent programming language, PHP uses variables.

PHP variables can store any data you wish. They start with a $ sign and contain alphanumerical characters, but must always start with a letter.

$example1 = "example";
echo $example1;

This will output the text "example".

Variables as the name suggest can be altered after they're declared.

$example1 = "altered example";

$example1 now contains "altered example" and the previous contents are gone.