PHP is a popular server-side, cross-platform, HTML embedded scripting language. PHP scripting from a College of Engineering user account should automatically be enabled. The files need to go into your public_html folder and need to be owned by you (should always be the case unless you've altered permissions allowing others access).

To verify that PHP is working for you, save a file called 'test.php' to your public_html directory. 

2. Inside 'test.php' type the following lines:

<html>
<head>
<title>My first PHP script</title>
</head>
<body>

<?php

/* the above "<?php" signals that the PHP script has begun */

$today = date("Y-m-d");

print "Today is: $today.";

/* the following "?>" closes the script */

?>
</body>
</html>

 

3. Save the file.

4. Launch your web browser and go to: (http://web.engr.oregonstate.edu/~your-username-here/test.php). If you have followed the above instructions carefully, the page you load should display the current date.

Some things to remember:

  1. Error reporting is off by default for the php cgi. To see error messages in your scripts, include the line "<?php ini_set('display_errors', 'On'); ?>" at the top of your script or page. Runtime directives for php have no effect when placed in .htaccess files under the cgi environment.
  2. PHP statements must be within the "<?php...?>" brackets.
  3. Comments are enclosed within "/*" and "*/" brackets, or by placing a "#" sign at the beginning of the line.
  4. Statements that are to be outputted to the screen must be enclosed in double quotations ("), and prefaced by the PRINT statement.
  5. Almost every PHP command must end in a semi-colon (;).
  6. Any HTML commands placed within the PRINT statements will be interpreted by the browser, and perform their usual actions.
  7. Documents including PHP statements must be saved with the extension *.php (For example, myphpfile.php). This tells the PHP interpreter to execute any commands found within the script. (Actually the extension used can be adjusted or new extensions can be added as indicated in the .htaccess example at the top of this document.
  8. Date command:
    Syntax: string date(string format, int timestamp);

    The function can take two variables (timestamp) is optional. If supplied with a timestamp, the function returns a string containing a date formatted according to the parameters within the format string. In the above example, Y-m-d signifies year, month, and day, respectively, all in numerical format. There are many other format characters that can be placed within the format string. For a complete list, click here.

 

Links to resources for learning PHP can be found at php.net.

A particularly good beginners tutorial is over at W3Schools.