Bagaimana Melihat Info Pelawat – Visitor Info

Bagaimana Melihat Info Pelawat – Visitor Info

Skrip PHP sudah tersedia untuk memaparkan maklumat pelawat ke web anda.

Skripnya cukup mudah.

visitor-info-demo

 

LIHAT DEMO

Apakah kod yang terlibat:

KOD HTML (Untuk bina Jadual seperti demo)

<table width="600" border="1" cellspacing="2" cellpadding="2">
  <tr>
    <td width="273"><h3>Perkara</h3></td>
    <td width="307"><h3>Info</h3></td>
  </tr>
  <tr>
    <td>IP Address</td>
    <td><?php echo $_SERVER['REMOTE_ADDR']?></td>
  </tr>
  <tr>
    <td>Sistem Operasi</td>
    <td><?php echo $platform ?></td>
  </tr>
  <tr>
    <td>Pelayar Web</td>
    <td><?php echo $bname?></td>
  </tr>
  <tr>
    <td>Versi Pelayar Web</td>
    <td><?php echo $version ?></td>
  </tr>
  <tr>
    <td>Halaman Rujukan ke Web ini</td>
    <td>
      <?php if (isset( $_SERVER["HTTP_REFERER"])) echo $_SERVER["HTTP_REFERER"]; else echo '<i>None</i>'?>
    </td>
  </tr>
</table>

 

Kod PHP

 

<!-- Powered By : BelajarPHP.com -->
<?php
	    $u_agent = $_SERVER['HTTP_USER_AGENT'];
	    $bname = 'Unknown';
	    $platform = 'Unknown';
	    $version= "";
 
	    //First get the platform?
	    if (preg_match('/linux/i', $u_agent)) {
	        $platform = 'linux';
	    }
	    elseif (preg_match('/macintosh|mac os x/i', $u_agent)) {
	        $platform = 'mac';
	    }
	    elseif (preg_match('/windows|win32/i', $u_agent)) {
	        $platform = 'windows';
	    }
 
	    // Next get the name of the useragent yes seperately and for good reason
	    if(preg_match('/MSIE/i',$u_agent) && !preg_match('/Opera/i',$u_agent))
	    {
	        $bname = 'Internet Explorer';
	        $ub = "MSIE";
	    }
	    elseif(preg_match('/Firefox/i',$u_agent))
	    {
	        $bname = 'Mozilla Firefox';
	        $ub = "Firefox";	        
	    }
	    elseif(preg_match('/Chrome/i',$u_agent))
	    {
	        $bname = 'Google Chrome';
	        $ub = "Chrome";
	    }
	    elseif(preg_match('/Safari/i',$u_agent))
	    {
	        $bname = 'Apple Safari';
	        $ub = "Safari";
	    }
	    elseif(preg_match('/Opera/i',$u_agent))
	    {
	        $bname = 'Opera';
	        $ub = "Opera";
	    }
	    elseif(preg_match('/Netscape/i',$u_agent))
	    {
	        $bname = 'Netscape';
	        $ub = "Netscape";
	    }
 
	    // finally get the correct version number
	    $pos=strpos($u_agent,$ub);
	    $m=$pos+strlen($ub)+1;
	    if ($ub=='MSIE')
	    	$l=strpos($u_agent,';',$m)-$m;
	    else
		    $l=strpos($u_agent,' ',$m)-$m;
		if ($l<=0) $l=10;
		$version=substr($u_agent,$m,$l);
?>

 

Leave a Reply

comment-avatar

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.