1 Environment Variables

<html><head><title> Environment Variables </title> </head><body>
<h3>Environment variables script</h3>
<p> Here are the CGI environment variables that this PHP script has been called with
foreach($_SERVER as $key => $value) {
echo ($key . "=" . $value ."<br>");
<h4>How to use just one environment variable:</h4>

1.1 Exercises

1) Try the script.

2) Use one of the PHP scripts that you have created earlier in this semester and that responds to a form. Include a print statement in the PHP script that prints the environment variables REQUEST_METHOD, QUERY_STRING and CONTENT_LENGTH. Note: that some of these are only available if the method for sending the form is "get", others are only available if the method is "post". (Check the <form action=... method=... > tag in your form.) REQUEST_METHOD and CONTENT_LENGTH can be used to increase the security of your script. CONTENT_LENGTH should not be longer than a predefined maximum length.

2 Customize Pages with PHP

PHP can show different pages to different users depending on user preferences.

2.1 Exercises

3) Ask a user to input their name into a textfield and to choose a color from a popup menu. Then display a page with a short message (e.g. "Thank you $_REQUEST['name'] for your request") in that color.