Forum Moderators: coopster

Message Too Old, No Replies

How to stop hotlinking for images?

want to change the destination url when right clicked

         

netchicken1

4:34 am on Apr 27, 2008 (gmt 0)

10+ Year Member



I have the images in my attachments load on my forum with the following code

$attachimage ="<img src=\"viewthread.php?action=attachment&amp;tid=$tid&amp;pid=$post[pid]\" title=\"$post[filename] - $attachsize\" alt=\"$post[filename] - $attachsize\"/>";

This works perfectly well, but I am having a problem with some sites hotlinkng to direct them.

To stop this all i have to do is take out the action=attachment part, which will make it show the thread instead of the image.

How can I do a str_replace like this

$attachimage = str_replace("action=attachment","",$attachimage);

after generatiing the image so that the hyperlink is changed that people right click on to copy the location?

RonPK

9:34 am on Apr 28, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



With PHP, you cannot change the source code of an HTML page once it has been downloaded. PHP runs on the server and thus can't respond to client-side user actions.

The usual way to prevent hotlinking is through a .htaccess file (if you're on Apache).