PHP: Only load site if it's referred from somewhere

5 replies
Hey,

Is there any way to only load a website if it's referred from somewhere...

So if someone's just handed the URL only a blank page loads up..

Trying to hide some of my landing pages from people..

Would appreciate any ideas!
#load #php #referred #site
  • Profile picture of the author Geraldm
    Hi Joe,

    If it's a standard apache web server you are using then add this to your .htaccess file:

    Code:
    RewriteEngine On  
    RewriteBase /  
    SetEnvIfNoCase Referer "^$" bad_user
    Deny from env=bad_user
    The above code will deny access to anyone coming to your website with no referrer information.

    Or you could do this:

    Code:
    RewriteEngine On  
    RewriteBase / 
    RewriteCond %{HTTP_REFERER} !.*yourdomain.*
    RewriteRule ^(.*)$ ^http://yourdomain.com/nothingtoseehere.php [R=301,L]
    Regards,
    Gerald.
    {{ DiscussionBoard.errors[8326994].message }}
    • Profile picture of the author Brandon Tanner
      ^ Keep in mind that 'referer' is not reliable. If someone types in your URL directly, no 'referer' will ever be set. It's only set if someone clicks an actual hyperlink from another site to your site (and even then it's not reliable, because not all browsers send referrer info, and some antivirus/firewalls, etc, will block it from being sent).

      FYI... you can also get the referer info via PHP ( $_SERVER['HTTP_REFERER'] ), but it has the same unreliability problem as the .htaccess method does.
      Signature

      {{ DiscussionBoard.errors[8327302].message }}
  • Profile picture of the author MikeOranguu
    Hey,

    If you're in control of the referral links, then a more reliable solution would be to append the get variable to the url and check for it in php. Then if the needed variable is there display your page, else show a blank/error page.

    It's very similar to the way affiliate links works, but instead of a user id, you could use a site id for where it came from.

    If need be you could set up a database table to validate against should you have multiple referrals or if individuals visitors have unique refferal codes.

    Let me know if you need any more help pointing you in the right direction.
    {{ DiscussionBoard.errors[8327454].message }}
    • Profile picture of the author David Beroff
      Originally Posted by MikeOranguu View Post

      If you're in control of the referral links, then a more reliable solution would be to append the get variable to the url and check for it in php. Then if the needed variable is there display your page, else show a blank/error page.
      Or require a cookie?
      Signature
      Put MY voice on YOUR video: AwesomeAmericanAudio.com
      {{ DiscussionBoard.errors[8332941].message }}

Trending Topics