WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Antispoof - a class to help prevent people hi-jacking and misusing parts of a website
Categories : PHP, PHP Classes, Security Update Picture
Simon Booth
Date : Aug 06th 2002
Grade : 4 of 5 (graded 8 times)
Viewed : 12655
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Simon Booth
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

<?php
// There should be no white space before the opening script tag

// Antispoof - Simon Booth (simon.booth@ukonline.co.uk) - 2002

// Antispoof - a little class and decendants to
// detect and/or prevent people hi-jacking and
// misusing parts of a website.
//
// Should be nice and easy to add further
// functionality to. The most common things that
// mean someone is spoofing you are set up below
//
// Example real-world use. Chuck one an antispoof_post
// in front of a generalised mailing script
// to stop 'web-marketeers' spamming the world
// using your web server as a unknowing relay.

// Example use...
// include("antispoof.php");
// $spoofer = new antispoof_self();
//
// You may optionally use the form...
//
// $spoofer = new antispoof_self(true);
//
// in which case you'll get some idea of what
// caused the supposed spoof (useful for debugging)
//
// Actual classes you'd instantiate are
// antispoof_get, antispoof_post and antispoof_self

// antispoof()
//
// Base class
//
// This does very little apart from
// setting up a load of variables for
// use by derived classes
//
// You will almost certainly want to modify
// the spoofed() method of this class!

class antispoof
 
{
  var
$host;              // Our webserver - www.somewhere.com
 
var $referer;           // The refering page
 
var $method;            // GET or POST
 
var $protocol;          // HTTP/1.1 for example
 
var $port;              // 80 in most cases, 443 for SSL
 
var $request_uri;       // The URI without the host
 
var $secure;            // Are we using HTTPS ?
 
var $getcount;          // How many GET variables were passes
 
var $postcount;         // How many POST variables were passes
 
var $internal_referal// Did we come from our own website ?
 
var $self_referal;      // Did we come from the same page ?
 
var $showerrors;        // Show errors when spoofed() - true/false
 
  // Main constructor - initialises everything
  // Optional $showerrors parameter controls
  // whether spoofed() member displays anything
  // or just bombs the script out

 
function antispoof($showerrors = false)
    {
   
$referer_uri_parts = parse_url($GLOBALS["HTTP_REFERER"]);
   
$script_uri_parts  = parse_url($GLOBALS["REQUEST_URI"]);

   
$this->host        = $GLOBALS["HTTP_HOST"];
   
$this->referer     = $GLOBALS["HTTP_REFERER"];
   
$this->method      = $GLOBALS["REQUEST_METHOD"];
   
$this->protocol    = $GLOBALS["SERVER_PROTOCOL"];
   
$this->port        = $GLOBALS["SERVER_PORT"];
   
$this->request_uri = $GLOBALS["REQUEST_URI"];
   
$this->secure      = ($GLOBALS["HTTPS"] == "on");
   
$this->getcount    = count($GLOBALS["HTTP_GET_VARS"]);
   
$this->postcount   = count($GLOBALS["HTTP_POST_VARS"]);
   
$this->internal_referal = ($referer_uri_parts["host"] === $GLOBALS["HTTP_HOST"]);
   
$this->self_referal = ($referer_uri_parts["host"] === $GLOBALS["HTTP_HOST"]) &&
                          (
$referer_uri_parts["path"] === $script_uri_parts["path"]);
   
$this->showerrors  = $showerrors;
    }

 
// Something broke the rules - stop the script!
  // Optionally show the message in $msg depending on
  // whether our constructor was passed true or false

 
function spoofed($msg)
    {
    if(
$this->showerrors === true)
      {
      echo
"Attempt to spoof the script<br>\n";
      echo
"Message: $msg<br>\n";
      }
    exit();
    }

 
// Debug - Dump out all the data we've got
 
 
function showme()
    {
    echo
"<pre>\n";
   
print_r($this);
    echo
"</pre>\n";
    }
  }


// antispoof_get()
//
// This version must have been called from
// another page on our website using GET
//
// This antispoof decendant checks that...
//
// We are called from somewhere on our own site
// Method is GET
// There are no POST variables

class antispoof_get extends antispoof
 
{
  function
antispoof_get($showerrors = false)
    {
   
// Initialise everything
   
parent::antispoof($showerrors);

   
// Must be called from our own site
   
if($this->internal_referal !== true)
     
parent::spoofed("External referer detected in an antispoof_get");

   
// Check method was GET
   
if($this->method !== "GET")
     
parent::spoofed("POST method used in an antispoof_get");

   
// POST variables count should be zero
   
if($this->postcount !== 0)
     
parent::spoofed("POST variables in an antispoof_get");
    }
  }


// antispoof_post()
//
// This version must have been called from
// another page on our website using POST
//
// This antispoof decendant checks that...
//
// We are called from somewhere on our own site
// Method is POST
// There are no GET variables

class antispoof_post extends antispoof
 
{
  function
antispoof_post($showerrors = false)
    {
   
// Initialise everything
   
parent::antispoof($showerrors);

   
// Must be called from our own site
   
if($this->internal_referal !== true)
     
parent::spoofed("External referer detected in an antispoof_post");

   
// Check method was GET
   
if($this->method !== "POST")
     
parent::spoofed("GET method used in an antispoof_post");

   
// GET variables count should be zero
   
if($this->getcount !== 0)
     
parent::spoofed("GET variables in an antispoof_post");
    }
  }


// antispoof_self()
//
// This version must have been called from
// another page on our website using GET
// or be self-calling using POST
//
// This kind of thing is a common way to
// handle forms on a site. You call the
// page with the form from a menu and when
// the form is submitted the target is the
// same page but some logic kicks in that
// validates stuff and writes to a database
// or whatever
//
// This antispoof decendant checks that...
//
// If the method is GET
// We are called from somewhere on our own site
// There are no POST variables
//
// If the method is POST
// We are self-calling (referer == this page)
// There are no GET variables

class antispoof_self extends antispoof
 
{
  function
antispoof_self($showerrors = false)
    {
   
// Initialise everything
   
parent::antispoof($showerrors);

    if(
$this->method === "GET")
      {
     
// Must be called from our own site
     
if($this->internal_referal !== true)
       
parent::spoofed("External referer detected in an antispoof_self");

     
// GET variables count should be zero
     
if($this->getcount !== 0)
       
parent::spoofed("GET variables in an antispoof_self");

     
// POST variables count should be zero
     
if($this->postcount !== 0)
       
parent::spoofed("POST variables in an antispoof_self when referer not self");
      }
    else if(
$this->method === "POST")
      {
     
// Must be called from our own site
     
if($this->self_referal !== true)
       
parent::spoofed("Referer for an antispoof_self in POST mode was not self");

     
// POST variables count should be zero
     
if($this->getcount !== 0)
       
parent::spoofed("GET variables in an antispoof_self");
      }
    else
      {
     
// Shouldn't get here - method was not GET or POST
     
parent::spoofed("antispoof_self method was not GET or POST");
      }
    }
  }

// There should be no white space after the closing script tag
?>



A damaged image generator (class) for validating text. CAPTCHA - Completely Automated Public Turing test to tell Computers and Humans Apart
Categories : PHP, PHP Classes, Security, GD image library, Security
PHP5 Security System
Categories : PHP, PHP Classes, Security
Scan Apache access log files and report possible worms attack
Categories : PHP, PHP Classes, Security, Apache, Log Files
Scramble Eggs - php class to scramble/encode
Categories : PHP, PHP Classes, Security, Encryption
Use of bitmasks to represent permissions
Categories : PHP, Authentication, Bitwise Operators, Security, PHP Classes
Forms protected from XSS attacks (FOPAXSS)
Categories : PHP, PHP Classes, Form Processing, Security
Generating and Matching Secure and Strong Password Hash
Categories : PHP, PHP Classes, Cryptography, Security
Function to generate readable/remeberable random password
Categories : PHP, Security, Security
Password Creator: This PHP code exmaple shows how to use bitwise operations on a single variable and using it as a flagged variable. The class generates passwords of a given length using specified characters and the flags.
Categories : PHP, PHP Classes, Algorithms, Security
IPhider Obscure Any URL Anonymity connection lores obfuscation corporate survival.
Categories : PHP, Algorithms, Security, URLs
Sort the results from a SELECT query (any number of columns) into an array automatically.
Categories : PHP, PHP Classes, Arrays, Databases, MySQL
usercounter class
Categories : PHP, PHP Classes, Databases, MySQL, Environment Variables
Most of the browsers, especially Internet Explorer, behave in different ways. Hence it become necessary to use Browser detection to fix the non standard behavior of the browser. This is a browser sniffer class that can be used for the above purpose.
Categories : PHP, PHP Classes, Browsers
Link Manager for Link Exchangers
Categories : PHP, PHP Classes, Databases, MySQL, CURL
Class to convert any document, that can be read by MS Word, to another format supported by Word.
Categories : PHP Classes, PHP, Windows 2000, Microsoft Word, WinNT