How to Prevent PHP Hotlinking
Views:
Author: Chris
Alright, it's been a long time since my last tutorial, sorry about the delay. Anyway, let's get stuck in!

What is Hotlinking?


Hotlinking can be illegal, it is basically where somebody runs a script, image etc off YOUR site causing YOU to pay for the bandwidth.
This code can also help stop hackers hacking your site by not allowing them access to your configuration file (if they ever find the path to it)

The Code


The code is simple, say if you want to protect your configuration file and only allow it to be accessed byu the files of your choosing, simply add this script to the top of your file:!

defined( 'random_letters&characters_here'  or exit( header("Location: http://www.tutnation.com/hotlinking/" );


This basically means that you have to run a code on the pages that CAN run the configuration script and if that code is not on the page it will exit and redirect to your website's hot linking page.

I hope you are understanding this so far, if not, try re-reading otherwise leave a comment below.

On the pages you do want to allow access to, simply put this code on each page. DO NOT give out your code, which in the example above is: "random_letters&characters_here" which, by the way, you should probably change.
Anyway, here is the code you need to add to the top of each page that you want to grant access to your configuration file.


<?php

define
('random_letters&characters_here',1); ?>



Without that code, you will be redirected to the page you told the script to exit to.

I hope that helps! Leave comments and questions below!



1



Comments
You must be logged in or register an account with us before posting a comment.
Statistics
Member Stats Online Members, read legend below: .
Registered Users: 5 registered AND activated.
Member Level Legend NOTE: If the username is underlined it means they may just have the page open and not actually be surfing the site. Administrator
Home

Membership Login

Shout Box

» GO FULL!
Please login to post a shout. » Turn OFF chat!

Point Leader board

© Copyright 2006 - 2008 Tutnation.com and ChrisTheFeral.com