As I have already installed Instant Rails which includes the Apache server, I didn't need to download it. When I looked at the folders in the Instant Rails directory, I realised that I already had PHP as well. Dropped the php_info.php file in the www directory under the InstantRails directory, started Instant Rails which started the Apache server, went back to the browser and tried http://localhost/php_info.php and it worked. Yah!!! The phpinfo command gives lots of great information on the PHP and Apache environments, mysql, environment variables, php variables and lots more which is really handy.
Question 1.
Copied the following code into my php file:
<HTML>
<HEAD>
</HEAD>
<BODY>
<?php
echo "You are connected from: ",$REMOTE_ADDR;
echo "<BR>";
?>
</BODY>
</HTML>
Rendered the page in the browser but it didn't work and I got the following error:
Notice: Undefined variable: REMOTE_ADDR in c:\instantrails\www\php\exercise6_1.php on line 6
I found an interesting article at http://us.php.net that explains that the $REMOTE_ADDR is no longer valid from php version 4.2.0. This is because the register_globals command has been deprecated and the Superglobal array should now be used. To use the Superglobal array you have to use $_SERVER['REMOTE_ADDR'] to get the same information.
A list of Apache and IIS Superglobal comparisons can be found at http://koivi.com/apache-iis-php-server-array.php.
Changed question 1 to the following:
<HTML>
<HEAD>
</HEAD>
<BODY>
<?php
echo "You are connected from: ",$_SERVER['REMOTE_ADDR'] ;
echo "<BR>";
echo "You are connected from: ", $_SERVER['SERVER_NAME'];
echo "<BR>";
echo "You are connected from: ", $_SERVER['PHP_SELF'];
echo "<BR>";
?>
</BODY>
</HTML>
The results of the above code is as follows:
You are connected from: 127.0.0.1
You are connected from: localhost
You are connected from: /php/Exercise6_1.php
Question 2.
Copied the following code into my php file:
<?php
$myvar = "Hello World!";
echo $myvar;
?>
The results of the above code is as follows:
Hello World!
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment