Only allow _POST's from your domain





5
Date Submitted Sun. May. 20th, 2007 10:58 PM
Revision 1 of 1
Scripter SecondV
Tags allow | deny | DOMAIN | PHP | post
Comments 3 comments
This small snippet will not allow _POST requests from a 'foreign' domain. It relies on the HTTP_REFERER variable.
<?php

/**
* Change 'yourdomain.com' to your domain name, no www.
* It's best to put this code in a global file (file that is included on all pages)
* before any other code.
*/

if (count($_POST) > 0)
{
    if ($_SERVER['HTTP_REFERER'])
    {
        $referrer_parts = @parse_url($_SERVER['HTTP_REFERER']);
        $ref_port = intval($referrer_parts['port']);
        $ref_host = $referrer_parts['host'] . (!empty($ref_port) ? ":$ref_port" : '');

        if (strpos($ref_host, 'yourdomain.com') === false)
        {
            die();
        }
    }
}

?>

Eric S.

www.secondversion.com
-SV

Comments

Comments Spoofing
Wed. Apr. 2nd, 2008 3:43 PM    Scripter sehrgut
Comments Token?
Wed. Aug. 29th, 2007 9:34 AM    Beginner Tr0y
Comments =]
Tue. Jun. 26th, 2007 11:05 PM    Newbie loibe

Voting