PHP is a popular server-side, cross-platform, HTML-embeddable 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).
1. 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:
<?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.<?php
) and end (?>
) tags./*
and */
. Single-line comments can be made by placing a #
or //
at the beginning of the line.print
or echo
statements will be interpreted by the browser, and perform their usual actions.Links to resources for learning PHP can be found at php.net.
A particularly good beginners tutorial is over at W3Schools.