PHP: Solution 1


Introduction | Static vs. Dynamic Websites | Using PHP on RCI or Eden | A Simple PHP Program | Practice 1 | Loops | Practice 2 | Functions | Practice 3 | Conditionals | Practice 4 | PHP and Online Forms | Practice 5 | PHP and E-mail | Practice 6 | Conclusion


The solution to practice 1 is:

<html>
<p>You are using
<? echo "$HTTP_USER_AGENT"; ?><br>
and coming from
<? echo "$REMOTE_ADDR"; ?><br>
</html> 


Note: In the above example (and when working with varialbes in general) it is not necessary for you to put your variables in quotes ("). You could have written:

<? echo $HTTP_USER_AGENT; ?><br>

If the above didn't work for you it might be becuase the PHP that you're working with doesn't have Register Globals turned on. Try making the following variation:

<html>
<p>You are using
<?php echo $_SERVER['HTTP_USER_AGENT']; ?><br>
and coming from
<?php echo $_SERVER['REMOTE_ADDR']; ?><br>
</html> 

PHP has other web-related variables which you can echo back to your users. To see what variables are available to you on RCI click here. To see what variables are available to you on Eden click here. Then scroll to the table titled "Apache Environment". The file info.php3 runs a built-in PHP function (there will be more information on functions later) which displays information particular to the webserver that is running PHP scripts. The information you see pertains specifically to RCI or Eden and is never out of date since it is updated everytime the page is loaded.



edseries@nbcs.rutgers.edu