Login   Register  
PHP Classes
elePHPant
Icontem

File: example_5.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Todor Iliev  >  Defensive Attack  >  example_5.php  >  Download  
File: example_5.php
Role: Example script
Content type: text/plain
Description: Class extends. Check referer with "www" and without "www".
Class: Defensive Attack
Retrieve information of current user HTTP request
Author: By
Last change:
Date: 2006-11-01 08:22
Size: 2,069 bytes
 

Contents

Class file image Download
<?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 === (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) == 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";
}


?>