Dr. Mark Humphrys

School of Computing. Dublin City University.

Home      Blog      Teaching      Research      Contact

Search:

CA216      CA249      CA318

CA400      CA651      CA668


PHP demo


This PHP program on the server side:


 

<?php 

       $clientip=$_SERVER['REMOTE_ADDR'];
 $clienthostname=$_SERVER['REMOTE_HOST'];
$clienthostname2=gethostbyaddr($clientip);

     $originalip=$_SERVER['HTTP_X_FORWARDED_FOR'];

 $clientbrowser=$_SERVER['HTTP_USER_AGENT'];
      $referrer=$_SERVER['HTTP_REFERER'];

      $serverip=$_SERVER['SERVER_ADDR'];
    $servername=$_SERVER['SERVER_NAME'];
$serversoftware=$_SERVER['SERVER_SOFTWARE'];


 $serverOSlong=php_uname();
$serverOSshort=PHP_OS;


// execute a shell command:
        $output=shell_exec("ps -p $$ -o user,ruser");


// time in seconds since 1970:
     $seconds=time();


$t=gettimeofday();              // returns array of seconds since 1970, plus microseconds 
$microseconds=$t["usec"];       // see also microtime 

   $human_date=date("r");

$microsecondid=uniqid();
          $pid=getmypid();


print "<table border=1 CELLPADDING=5 cellspacing=0  bgcolor=#eeeeee>\n"; 
print "<tr> <td> Client IP                                                          </td> <td> $clientip                  </td> </tr>\n";  
print "<tr> <td> Client hostname as environment variable (if set up)        </td> <td> $clienthostname    </td> </tr>\n";  
print "<tr> <td> Client hostname (done manually)                            </td> <td> $clienthostname2           </td> </tr>\n";  
 
print "<tr> <td> Query client IP  </td> <td> \n"; 
print "<form action=http://www.domaintools.com/go/ method=get >";
print "<input type=hidden name=service value=whois >";
print "<input name=q type=text value=$clientip size=20 >";
print "<INPUT TYPE=submit VALUE=Search >";
print "</FORM>";
print "</td> </tr>\n"; 

print "<tr> <td> Original IP (if indirect)  </td> <td> $originalip                                        </td> </tr>\n";  

print "<tr> <td> Client browser             </td> <td> $clientbrowser                             </td> </tr>\n";  
print "<tr> <td> Referring page (if any)    </td> <td> <a href=$referrer>$referrer</a>        </td> </tr>\n";  
print "</table><p>\n"; 

print "<table border=1 CELLPADDING=5 cellspacing=0  bgcolor=#eeeeee>\n"; 
print "<tr> <td> Server IP                  </td> <td> $serverip                                          </td> </tr>\n"; 
print "<tr> <td> Server name                        </td> <td> $servername                                        </td> </tr>\n"; 
print "<tr> <td> Server software            </td> <td> $serversoftware                            </td> </tr>\n"; 

print "<tr> <td> Server OS (short)          </td> <td> $serverOSshort                             </td> </tr>\n"; 
print "<tr> <td> Server OS (long)           </td> <td> $serverOSlong                              </td> </tr>\n"; 


print "<tr> <td> Result of shell command  </td> <td> <pre> $output </pre>                            </td> </tr>\n"; 
print "</table><p>\n"; 

print "<table border=1 CELLPADDING=5 cellspacing=0  bgcolor=#eeeeee>\n"; 
print "<tr> <td> Seconds since 1 Jan 1970                                   </td> <td> $seconds           </td> </tr>\n"; 
print "<tr> <td> Time now - microsecond within the current second   </td> <td> $microseconds      </td> </tr>\n"; 
print "<tr> <td> Unique id based on time in microseconds            </td> <td> $microsecondid     </td> </tr>\n"; 
print "<tr> <td> Human-readable datestamp                                   </td> <td> $human_date                </td> </tr>\n"; 
print "<tr> <td> Process ID                                                         </td> <td> $pid                       </td> </tr>\n"; 
print "</table><p>\n"; 


?>



 

Displays:


Client IP 54.90.159.192  
Client hostname as environment variable (if set up)  
Client hostname (done manually) ec2-54-90-159-192.compute-1.amazonaws.com  
Query client IP
Original IP (if indirect)  
Client browser CCBot/2.0 (http://commoncrawl.org/faq/)  
Referring page (if any)  

Server IP 136.206.217.25  
Server name computing.dcu.ie  
Server software Apache/2.4.23 (Linux/SUSE)  
Server OS (short) Linux  
Server OS (long) Linux ossa2 4.4.59-92.17-default #1 SMP Thu Apr 6 14:16:09 UTC 2017 (7bc489d) x86_64  
Result of shell command
 USER     RUSER
wwwrun   wwwrun
 

Seconds since 1 Jan 1970 1513567387  
Time now - microsecond within the current second 52743  
Unique id based on time in microseconds 5a37349b0d9df  
Human-readable datestamp Mon, 18 Dec 2017 03:23:07 +0000  
Process ID 4751  





Feeds      w2mind.org

On Internet since 1987.