<?php 

 $REMOTE_ADDR
=$_SERVER['REMOTE_ADDR']; 
 
$REMOTE_HOST=$_SERVER['REMOTE_HOST'];
 
$HTTP_USER_AGENT=$_SERVER['HTTP_USER_AGENT'];
 
$HTTP_REFERER=$_SERVER['HTTP_REFERER'];
?>

<h2>Browser Identification</h2>

The following information is available to any web server you
connect to. 
See the <a href="browser.phps">php code</a> for details.
<p>

 <table BORDER COLS=4 WIDTH="700" NOSAVE >
  <tr bgcolor="#FFCC00">
    <td colspan=2 align=left>browser information
  </tr>
  <tr>
    <td WIDTH=30%>IP-Address</td>
    <td WIDTH=70%><?php echo $REMOTE_ADDR ?></td>
  </tr>
  <tr>
    <td WIDTH=30%>DNS-Name</td>
    <td WIDTH=70%><?php echo $REMOTE_HOST ?></td>
  </tr>
  <tr>
    <td WIDTH=30%>User-Agent</td>
    <td WIDTH=70%><?php echo $HTTP_USER_AGENT ?></td>
  </tr>
  <tr>
    <td WIDTH=30%>HTTP-Referer</td>
    <td WIDTH=70%><?php echo $HTTP_REFERER ?></td>
  </tr>
  <tr bgcolor="#FFCC00">
    <td colspan=2 align=left>entire request sent by your browser
  </tr>
  <tr>
   <td colspan=2>
    <?php
      $headers 
getallheaders();
      while (list (
$header$value) = each ($headers)) {
        echo 
"$header: $value<br>\n";
      }
    
?>
 </table>
 <h4>Cookie Demonstration</h4>
 <?php
  
// random name generator just for fun
  
function random_name(){
    
// Top UK baby names 2004 :-)
    // http://www.babycentre.co.uk/pregnancy/naming/topnames2004/
    
$boys=array("Jack""Joshua""Thomas""James",
    
"Daniel""Samuel""Oliver",
    
"William""Benjamin""Joseph""Harry""Matthew""Lewis""Ethan",
    
"Luke""Charlie""George""Callum""Alexander""Mohammed""Ryan",
    
"Dylan""Jacob""Adam""Ben""Jake""Alfie""Connor""Cameron",
    
"Liam""Nathan""Harvey""Jamie""Owen""Tyler""Max""Louis",
    
"Kyle""Michael""Kieran""Aaron""Bradley""Edward""Brandon",
    
"Alex""Archie""Harrison""Henry""Charles""Toby");
    
$girls=array("Emily""Ellie""Jessica""Sophie",
    
"Chloe""Lucy""Olivia",
    
"Charlotte""Katie""Megan""Grace""Hannah""Amy""Ella",
    
"Mia""Lily""Abigail""Emma""Amelia""Molly""Lauren",
    
"Millie""Holly""Leah""Caitlin""Rebecca""Georgia",
    
"Bethany""Eleanor""Isabelle""Ruby""Daisy""Freya",
    
"Isabella""Elizabeth""Jasmine""Erin""Alice""Evie",
    
"Amber""Paige""Abbie""Madison""Phoebe""Poppy""Aimee",
    
"Courtney""Niamh""Anna""Isabel");
    
// http://www.dolltoy.com/uk2.html
    
$surnames=array("Smith""Jones""Williams""Brown""Taylor""Davies",
    
"Wilson""Evans""Thomas""Johnson""Roberts""Walker",
    
"Wright""Robinson""Thompson""White""Hughes""Edwards",
    
"Green""Hall""Wood""Harris""Lewis""Martin""Jackson",
    
"Clarke""Clark""Turner""Hill""Scott""Cooper""Morris",
    
"Ward""Moore""King""Watson""Baker""Harrison""Morgan",
    
"Patel""Young""Allen""Mitchell""James""Anderson",
    
"Phillips""Lee""Bell""Parker""Davis");
    
// decide whether boy or girl names, prob more guys will check
    // this site, say 65%
    
if(mt_rand(1,100)<=65){
      
$index=mt_rand(0,sizeof($boys)-1);
      
$name=$boys[$index];
    } else {
      
$index=mt_rand(0,sizeof($girls)-1);
      
$name=$girls[$index];
    }
    
// add surname
    
$index=mt_rand(0,sizeof($surnames)-1);
    
$name="$name $surnames[$index]";
    return 
$name;
  }

  
// cookies, yeah fun!
  // ------------------
  
$cookie_expiry=time()+3600;

  if(isset(
$_COOKIE["user"])){
    
$user=$_COOKIE["user"];
    
$lastvisit=$_COOKIE["time"];
    print(
"Hello <b>$user</b>, you have last visited this page ");
    print(
time()-$lastvisit);
    print(
" sec ago.\n");
  } else {
    
// generate a new name
    
$user=random_name();
    print(
"Hello my friend, you have not got a name yet.
    Let me give you one. Allow me to call you <b>$user</b> from now on."
);
  }
  

  
// update/set cookies
  
setcookie("time"time(), $cookie_expiry);
  
setcookie("user"$user$cookie_expiry);
 
?>

 <p>
 If you are using Mozilla Firefox 2.0
 <?php
   
if(substr_count(strtolower($_SERVER['HTTP_USER_AGENT']), "firefox/2")>0){
    print(
"(and I think you are)");
   } else {
    print(
"(but I think you aren't, sorry that might not apply then)");
   }
 
?>
 you can browse all cookies by going to
 Edit &rarr; Preferences &rarr; Privacy &rarr; Show Cookies.
 
 Your browser will always send all cookies stored by one domain to
 all pages of that domain. This is done voluntarily, i.e. the web server
 does not requests to read a cookie. It is therfore not possible for
 a web server to gain access to cookies stored by a different domain
 (except in special circumstances when a web site calls a script
 from a different server).
 <br>
 To see all cookies available to this domain see the <em>Cookie</em> field
 in the table above. 
 </p>

 <p><em>Note, cookies set on this page will automatically expire
    after one hour.</em></p>