Referer Check

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
Namecheap AuctionsNamecheap Auctions
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
Close
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
Close
interesting. :) might come in handy some day. thnx
 
0
Close
Nice. I may implement this in a contact script I'm currently writing. Thanks.


-Eric
 
0
Close
Thanks for the code.It has helped me.
 
0
Close
Appraise.net

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back