Exercise 6: Examining environment variables
Since I do not have an UNIX account at CSU, I have to try the exercise at my desktop computer installed with Apache Server version 2.0.63, MySQL version 5.0.51a and PHP version 5.2.5.
I tried to examine the environment variable using the following codes as given in study guide:-
<HTML><HEAD></HEAD><BODY><?phpecho “You are connected from: “,$REMOTE_ADDR;echo “<BR>”;?></BODY>
</HTML>
The output would just be “You are connected from:” without the value of the environment variable of $REMOTE_ADDR. The reason might be due to the difference in OS platform or the version of PHP. I search the internet and able to find out the right programme codes for printing the environment variable as follows:-
<?php echo “You are connected from: “, $_SERVER['REMOTE_ADDR'];echo “<BR>”;
?>
The result of the output is You are connected from: 127.0.0.1.
Then I revise the codes as following:
<?php echo “The Server Name is: “, $_SERVER[‘SERVER_NAME'];echo “<BR>”;
?>
The output is “The Server Name is: localhost”
By examining the environment variable “PHP_SELF”, I then change the code as:
<?php echo “The Name of PHP File is: “, $_SERVER[‘PHP_SELF’];echo “<BR>”;
?>
The output is “The Name of PHP File is: /ITC594/ex6.php”
2. Create Hello_World.php
Programme codes of Hello_World.php are as follows:-
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd“>
<html xmlns=”http://www.w3.org/1999/xhtml“>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=big5″ />
<title>Hello World_PHP</title>
</head>
<body>
<?php
$myvar = “Hello World!”;
echo $myvar;
?>
</body>
</html>
View Hello_World.php using browser with a link: http://localhost/ITC594/hello_world.php
The output is just Hello World!