Referer check in PHP

by MariGanesh 2014-06-05 11:41:32

Referer check in PHP
                         use this following code for refere check in php.
<?php
/* Get Domain from url */


function GetDomain($url)
      {
    $nowww = ereg_replace('www.','',$url);
    $domain = parse_url($url);
         if(!empty($domain["host"]))
      {
       return $domain["host"];
       } else
       {
       return $domain["path"];
       }
       
      }

/*Referer Check Function */


      function referer_check()
      {
    global $display;
    $ref_url=$_SERVER['HTTP_REFERER'];
    $domainname=$display->GetDomain($ref_url);
    $servername=$_SERVER['HTTP_HOST'];
    if($domainname==$servername)
    {
      return true;
    }
    else
    {
      return false;
    }
     }

/*How to call Referer Check Function */


  if(referer_check())
   {
     /*  Your code Here */
   }


?>
 

Tagged in:

665
like
0
dislike
0
mail
flag

You must LOGIN to add comments