Combine two PHP cloaking scripts - how?

Discussion in 'PHP' started by Ithilnet, May 2, 2007.

  1. #1
    Hello to all. I have to combine two cloaking scripts but I'm making some mistakes and can't get them to work.

    The complete script should perform this task:

    the visitor comes in the page, the first cloaking script checks the REFERER, if it is DOMAIN.COM it executes the second cloaking script, else it displays PHP_3.
    The second cloaking script checks the BROWSER, if it is IE it displays HTML_1, else (FF, netscape or whatever), it displays HTML_2



    ****************************
    VISITORS CLOAKING SCRIPT
    ****************************

    
    <?php
    
    $match = false;
    $sites = array("myeditor.biz", web001.org);
    
    if(strlen($_SERVER['HTTP_REFERER']))
    {
        $referer = parse_url($_SERVER['HTTP_REFERER']);
               
        $referer['host'] = str_replace("www.", "", strtolower($referer['host']));
    
        $match = in_array($referer['host'], $sites);
    }
    
    
    if($match)
    {
    
    ?>
    
    <html>
    
    <head>
    <title>Page 1</title>
    </head>
    
    <body>
    for the cloaked visitors, here's the HTML_1
    </body>
    
    </html>
    
    <?php
    
    }
    else
    {
    
    ?>
    
    <html>
    
    <head>
    <title>Page 2</title>
    </head>
    
    <body>
    YOU CAME FROM SOMEWHERE ELSE, HERE'S THE HTML_2
    </body>
    
    </html>
    
    <?php
    
    }
    
    ?>
    
    </body>
    </html>
    
    PHP:
    ****************************
    BROWSER CLOAKING SCRIPT
    ****************************

    
    <?php
    function _get_browser()
    {
     $browser = array ( //reversed array
      "OPERA",
      "MSIE",            // parent
      "NETSCAPE",
      "FIREFOX",
      "SAFARI",
      "KONQUEROR",
      "INTERNETSEER"
     );
     
     $info[browser] = "OTHER";
     
     foreach ($browser as $parent) 
     {
      if ( ($s = strpos(strtoupper($_SERVER['HTTP_USER_AGENT']), $parent)) !== FALSE )
      {           
        $f = $s + strlen($parent);
        $version = substr($_SERVER['HTTP_USER_AGENT'], $f, 5);
        $version = preg_replace('/[^0-9,.]/','',$version);
                 
        $info[browser] = $parent;
        $info[version] = $version;
        break; // first match wins
      }
     }
     
     return $info;
    }
    $info=_get_browser();
    $browser=$info[browser];
    ?>
    
    PHP:
    ****************************
    PHP_3 EXAMPLE
    ****************************


    
    <?php
      // Hello World in PHP
      echo 'Hello World!';
    ?>
    
    PHP:



    The question is, how do I mix all this stuff togheter?
    Thanks in advance
     
    Ithilnet, May 2, 2007 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    I would do somthing like this:

    
    <?php
    function _get_browser()
    {
     $browser = array ( //reversed array
      "OPERA",
      "MSIE",            // parent
      "NETSCAPE",
      "FIREFOX",
      "SAFARI",
      "KONQUEROR",
      "INTERNETSEER"
     );
     
     $info[browser] = "OTHER";
     
     foreach ($browser as $parent) 
     {
      if ( ($s = strpos(strtoupper($_SERVER['HTTP_USER_AGENT']), $parent)) !== FALSE )
      {           
        $f = $s + strlen($parent);
        $version = substr($_SERVER['HTTP_USER_AGENT'], $f, 5);
        $version = preg_replace('/[^0-9,.]/','',$version);
                 
        $info[browser] = $parent;
        $info[version] = $version;
        break; // first match wins
      }
     }
     
     return $info;
    }
    
    $match = false;
    $sites = array("myeditor.biz", web001.org);
    
    if(strlen($_SERVER['HTTP_REFERER']))
    {
        $referer = parse_url($_SERVER['HTTP_REFERER']);
               
        $referer['host'] = str_replace("www.", "", strtolower($referer['host']));
    
        $match = in_array($referer['host'], $sites);
    }
    
    
    if($match){
    
    	$browser = _get_browser();
    	
    	if($browser['browser'] == 'MSIE'){
    	//the browser is internet explorer
    	$title = 'Page 1';
    	$output = 'Internet Explorer';
    		
    	
    	} else if ($browser['browser'] == 'FIREFOX'){
    	//the browser is mozilla
    	$title = 'Page 2';
    	$output = 'Mozilla';
    	
    	
    	} else {
    	//the browser is something else
    	$title = 'Page 3';
    	$output = 'Other';
    	
    	
    	}
    
    
    
    } else {
    //user not refered from domain
    $title = 'Page 4';
    $output = 'Not from domain';
    
    }
    
    ?>
    
    <html>
    
    <head>
    <title><?php echo $title; ?></title>
    </head>
    
    <body>
    <?php echo $output; ?>
    </body>
    
    </html>
    
    PHP:
     
    jestep, May 2, 2007 IP