NameSilo

Referer Check

Spaceship Spaceship
Watch

Outer

Established Member
Impact
2
I use this code each time a form is submitted to check to make sure external scripts aren't run when a user wants to submit the data

It also has other uses. Basically an extra security precaution

PHP:
<?php
// Set this to your domain name
$referer = "domain.com";

// Explode the HTTP_REFERRER address to split up the string
$ref = explode('/', $_SERVER['HTTP_REFERER']);

// next piece of code checks for the 'www.'
// Some people use http://domain.com and others use http://www.domain.com. This will remove the 'www.' as to let users have their choice
if (strstr($ref['2'], 'www.')) { $ref['2'] = str_replace('www.', '', $ref['2']); }

// check if they match or not
if ($ref['2'] != $referer)
{
    echo "You are not allowed to enter information from an external form.";
}
else
{
    // Continue with script
}
 
1
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Oh well, very nice idea actually. Thanks for this
:wave:
 
0
•••
interesting. :) might come in handy some day. thnx
 
0
•••
Nice. I may implement this in a contact script I'm currently writing. Thanks.


-Eric
 
0
•••
Thanks for the code.It has helped me.
 
0
•••

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Zero Commission
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back