WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Mobile Dev World

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : This program implements hot link prevention in php. It is useful for webmasters who do not have access to the server at a level where they can control hot linking can still supply some type of hot link prevention for thier site by using php.
Categories : PHP, Filesystem, Graphics, Content Management Click here to Update Your Picture
Tom Enders
Date : Nov 19th 2003
Grade : 2 of 5 (graded 5 times)
Viewed : 7269
File : 3760.zip
Images : No Images for this code example.
Search : More code by Tom Enders
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

This attached file is a script that allows you to perform hotlink prevention in pure php, for those that cannot do .htaccess or other methods. It includes full documentation on getting it up and running. More scripts available at http://www.suryvial.com.


<?php
/*
Copyright (C) 2003 Enders Web Development

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with
this program; if not, write to the
Free Software Foundation, Inc.,
59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.

Author Email: tomender@ptd.net
Author Post:
J. Thomas Enders
PO Box 663
Gilbert, PA 18331, USA
*/
error_reporting(E_ALL);

//where, in relation to this script, are the files stored
define(FILE_DIR,'.');
define(MY_URL,'suryvial.com');


//set up the array of types the system recognizes
$file_types = array(
   
'jpg' => array('image/jpeg','hotlinker.jpg'),
   
'gif' => array('image/gif','hotlinker.gif'),
   
'png' => array('image/png','hotlinker.png')
);

//make sure the script was called with the correct parameters
if(!isset($_GET['File']) || !isset($_GET['Type'])) {
    die(
'Required Parameters Not Specified');
} elseif(!
file_exists($_GET['File'])) {
    die(
'Invalid File Specified');
} elseif(!isset(
$file_types[$_GET['Type']])) {
    die(
'Invalid Type Specified');
}
//end if

//check if the link originated from our site
if(!ereg(MY_URL,$_SERVER['HTTP_REFERER'])) {
   
//reset the file to be the one we point hotlinkers to
   
$_GET['File'] = $file_types[$_GET['Type']][1];
}
//end if
   
//send out the headers for this file
header('Last-Modified: ' . date('D, d M Y G:i:s T',filemtime($_GET['File'])));
header('Accept-Ranges: bytes');
header('Content-Length: ' . filesize($_GET['File']));
header('Connection: close');
header('Content-Type: ' . $file_types[$_GET['Type']][0]);

//send the file to the browser
$file = fopen($file_dir . '/' . $_GET['File'],'r');
while(!
feof($file)) {
    print(
fread($file,4096));
   
flush();
}
//end while
fclose($file);
?>



Download manager - A PHP script for adding a download page to any site.It also enables you track the no. of downloads.
Categories : PHP, Content Management, Filesystem, Databases, MySQL
Image Browser
Categories : Filesystem, GD image library, Content Management, PHP
Random Image Display
Categories : PHP, Filesystem, Graphics, HTML and PHP
Read DPI value from image with PHP
Categories : PHP, Graphics, Filesystem
This is a simple photo gallery that reads the image files from multiple directories, and generates a web page styled with CSS1. It opens single auto window to view and print a given image.
Categories : Graphics, Filesystem, PHP, Complete Programs
Easy slideshow with php. Just place this one file into a subdirectory where jpg files reside. An instant slideshow is yours. MS explorer only.
Categories : PHP, Filesystem, Graphics
QTO File Manager
Categories : Filesystem, filePro, Complete Programs, PHP, Content Management
Simple image counter
Categories : PHP, Graphics, Filesystem, Beginner Guides
File Explorer, browse, upload, download and edit your web site files with only a browser and a HTTP connection.
Categories : Complete Programs, Content Management, Filesystem, PHP
This script will read all images from a folder and read the files into an array. It uses rand() to get a random number. It will display a random image from the image folder given.
Categories : PHP, Arrays, Graphics, Filesystem
Variable serialization and unserialization. Loading and saving variable structures to and from file.
Categories : Arrays, Filesystem, Variables, Strings, PHP
An efficient iterative and buffered text file reader
Categories : PHP, Classes and Objects, Filesystem, PHP Classes, Log Files
Create Thumbnails - resize an image - jpeg, jpg, gif, png to the specifed width and height in proportion without loosing out on pixcel quality.
Categories : PHP, GD image library, Graphics
filesystem Show Files Script
Categories : PHP, Filesystem, Java Script
upload function using PHP's FTP abilities.
Categories : PHP, Filesystem, HTML and PHP