<?php
/**
* File containing example 5(check referer with "www" and without "www") use DefensiveAttack.
*
* @package DefensiveAttack
* @version 1.0.0
* @copyright Copyright (C)2006 TheLordOfWeb. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @filesource
*/
//Load class DefensiveAttack
require("class.php5.DefensiveAttack.php");
/**
* MyDefensiveAttack class for php 5.x
*
*
* @package MyDefensiveAttack extends by DefensiveAttack
* @author TheLordOfWeb <http://thelordofweb.atspace.com/>
* @version 1.0.0
* @copyright Copyright (C)2006 TheLordOfWeb. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @example example_5.php
*/
class MyDefensiveAttack extends DefensiveAttack {
/**
* My host name 2 with "www" or not
*
* @access protected
* @var string
*/
protected $mMyHostName2 = '';
/**
* MyDefensiveAttack constructor
*
* @access public
* @param string hostname
* @see parent::__construct()
*/
public function __construct($myHostName = null) {
parent::__construct($myHostName);
$pos = stripos($this->mMyHostName,'www.');
$this->mMyHostName2 = (false !== $pos AND 0 === (int)$pos) ? substr($this->mMyHostName,4) : "www." . $this->mMyHostName;
}
/**
* Check referer for my url address with "www" and without "www"
*
* @access public
* @return bool
*/
public function CheckReferer() {
return (strcmp($this->mMyHostName,$this->mReferer) == 0 OR strcmp($this->mMyHostName2,$this->mReferer) == 0) ? true : false;
}
}
//Create object
$def_attack = new MyDefensiveAttack('mysite.com');
//Check referer if I do not want direct access to my site
if (false === $def_attack->CheckReferer()) {
print "Access deny " . '<a href="example_5.php" >Use link</a>';
} else {
print "Access allow";
}
?>
|