PHP Variables
PHP Code Examples
[Download]   [Execute]
<!-- This part is just plain HTML. -->
<html><head><title>PHP Variables</title></head>
<body style="background-color: #EFEFFF;">
<img src="http://sandbox.mc.edu/~bennet/icons/bibart.gif" 
	style="height: 3px; width: 100%; ">
<img src="http://sandbox.mc.edu/~bennet/icons/msplash3.gif" 
	style="float: right;">
<div style="color: #050b82; padding-top: 10px;">
<span style="font-size: 180%; font-weight: bold; ">PHP Variables</span>
	<div style="padding-top: 5pt;"><a href="../index.html"><img 
	src="http://sandbox.mc.edu/~bennet/icons/up3.gif" style="border: 0pt; 
	padding-right: 5pt; padding-left: 15pt; 
	vertical-align: middle;"><i>PHP Code Examples</i></a></div>
</div>
<img src="http://sandbox.mc.edu/~bennet/icons/bibar.gif" style="height: 3px; 
	width: 100%; margin-bottom: 10pt; 
	clear: right; ">

<?php
// PHP variables always start with $.  (Unlike perl, all variables start with
// $, including aggregates.)
$fred = 17;
$barney = 3 + $fred;
$alice = "Do you know the way to San Jose?";
echo $fred, " ", $barney, " ", $alice
?>

<p><hr><br>
Turn left at Albuquerque.
<br><hr><p>

<script language="php">
// This is another wayt to enter PHP.  And variable values survive between
// PHP regions.
echo '$barney has the value ', $barney, ".<br>";
</script>

<i>This is plain HTML.</i>

<p><table>
<?php
// There are many pre-defined variables which describe the script's 
// environment.

echo "<tr><td><b>My URL is:</b>:</td><td>http://",
	$_SERVER["SERVER_NAME"], ":", $_SERVER["SCRIPT_NAME"], "</td></tr>";
echo "<tr><td><b>Your browser is</b>:</td><td>",
	$_SERVER["HTTP_USER_AGENT"], "</td></tr>";
echo "<tr><td><b>Your IP address is</b>:</td><td>",
	$_SERVER["REMOTE_ADDR"], "</td></tr>";
?>
</table></p>

</body>
</html>