Results 1 to 2 of 2
-
22nd Jul 2010, 02:52 PM #1OPMemberWebsite's:
Doxsters.netSmart404
Hey guys, I just finished coding my "smart" 404 script and I thought i'd release it.
Release for www.chrixel.com (a awesome web coding and design forum) but I thought i'd post it here and hopefully get chrixel a bit of traffic
Heres the contents of the readme in there because I really can't be bothered to type it up again
################################################## ################
Smart404 Script, created by timtamboy63 for released for www.chrixel.com
################################################## ################
IMPORTANT NOTE:
This will only work if you have apache as it utilises the .htaccess file.
If you are on another web server but can redirect the 404 page, then you must redirect to:
/smart404/404.php
Usage:
If you don't already have a htaccess, just extract the smart404.zip to your the root of your
webspace(www or htdocs normally).
If you do have a .htaccess file set up, upload the smart404 folder to the root of your webspace and add the
following line to your htaccess
ErrorDocument 404 /smart404/404.php
NOTE: This will remove any custom 404 page you may have set up, but its fairly easy to get that back if you
know basic php.
What this script does:
Lets say you have a document called yay.php
You link a friend to it but they type in yay.html
Now normally they would get an error page, but with this script, they get redirected to yay.php
How smart!
Whats more, this takes the type of file into account.
For example, if you have test.php and test.wav, and someone types in test.mp3, chances are they're looking for
the test.mp3(they're both audio files) and so it redirects them to the test.mp3
Here's the code if anyone's interested but really can't be bothered downloading:
PHP Code:error_reporting(E_ALL);
//function to print out the begnning part of the url
function pageURL() {
$pageURL = 'http://';
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"];
}
return $pageURL;
}
//this function checks whether there is a file of the same name & extension in the array Data
function checkInData(){
global $data, $file, $dirpath, $endsplit;
foreach($data as $newext){
$file = '/' . $dirpath . $endsplit['0'] . '.' . $newext;
/* Was for debugging purposes only
print "
[b]Full: [/b]" . $_SERVER['DOCUMENT_ROOT'] . $file . '
';
print "[b]File: [/b]" . $file;
*/
if(file_exists($_SERVER['DOCUMENT_ROOT'] . $file)){
header("Location: $file"); exit;
}
}
}
//this function checks whether there is a file of the same name & extension in the array Img
function checkInImg(){
global $img, $file, $dirpath, $endsplit;
foreach($img as $newext){
$file = '/' . $dirpath . $endsplit['0'] . '.' . $newext;
/* Was for debugging purposes only
print "
[b]Full: [/b]" . $_SERVER['DOCUMENT_ROOT'] . $file . '
';
print "[b]File: [/b]" . $file;
*/
if(file_exists($_SERVER['DOCUMENT_ROOT'] . $file)){
print "[size="20px"] SUCCESS FOR $file[/size]";
header("Location: $file"); exit;
}
}
}
//this function checks whether there is a file of the same name & extension in the array Audio
function checkInAudio(){
global $audio, $file, $dirpath, $endsplit;
foreach($audio as $newext){
$file = '/' . $dirpath . $endsplit['0'] . '.' . $newext;
/* Was for debugging purposes only
print "
[b]Full: [/b]" . $_SERVER['DOCUMENT_ROOT'] . $file . '
';
print "[b]File: [/b]" . $file;
*/
if(file_exists($_SERVER['DOCUMENT_ROOT'] . $file)){
print "[size="20px"] SUCCESS FOR $file[/size]";
header("Location: $file"); exit;
}
}
}
//this function checks whether there is a file of the same name & extension in the array Video
function checkInVideo(){
global $video, $file, $dirpath, $endsplit;
foreach($video as $newext){
$file = '/' . $dirpath . $endsplit['0'] . '.' . $newext;
/* Was for debugging purposes only
print "
[b]Full: [/b]" . $_SERVER['DOCUMENT_ROOT'] . $file . '
';
print "[b]File: [/b]" . $file;
*/
if(file_exists($_SERVER['DOCUMENT_ROOT'] . $file)){
print "[size="20px"] SUCCESS FOR $file[/size]";
header("Location: $file"); exit;
}
}
}
//this function checks whether there is a file of the same name & extension in the array Comp(Compressed)
function checkInComp(){
global $comp, $file, $dirpath, $endsplit;
foreach($comp as $newext){
$file = '/' . $dirpath . $endsplit['0'] . '.' . $newext;
/* Was for debugging purposes only
print "
[b]Full: [/b]" . $_SERVER['DOCUMENT_ROOT'] . $file . '
';
print "[b]File: [/b]" . $file;
*/
if(file_exists($_SERVER['DOCUMENT_ROOT'] . $file)){
print "[size="20px"] SUCCESS FOR $file[/size]";
header("Location: $file"); exit;
}
}
}
//arrays of common datatypes
$img = array('bmp', 'gif', 'jpg', 'jpeg', 'png', 'tif');
$data = array('asp', 'cer', 'csr', 'css', 'htm', 'html', 'js', 'jsp', 'php', 'rss', 'xhtml');
$audio = array('aac', 'aif', 'iff', 'mp3', 'mpa', 'ra', 'wav', 'wma');
$video = array('3g2', '3gp', 'asf', 'asx', 'avi', 'flv', 'mov', 'mp4', 'mpg', 'rm', 'swf', 'vob', 'wmv');
$comp = array('7z', 'deb', 'gz', 'pkg', 'rar', 'sit', 'sitx', 'tar.gz', 'zip', 'zipx');
$url = $_SERVER['REQUEST_URI'];
$urlarray=explode('/', $url);
$dirs = $urlarray;
array_pop($dirs);
//$dirs now contains all the directories for the path
$dirpath ='';
foreach($dirs as $value){
$dirpath .= $value . '/';
}
$dirpath = substr($dirpath, 1);
//$dirpath contains the directory listing for the url
$last = count($urlarray);
$last = $last - 1;
$secondlast = $last -1;
$end = $urlarray[$last];
$endsplit=explode('.', $end);
//endsplit['0'] is the file name, endsplit ['1'] is the extension
if(!isset($endsplit['1'])){
$endsplit['1'] = 'html';
}
$ext = $endsplit['1'];
$oldurl = pageurl();
//these if,elseif and else order them and make it more likely to get it right. Eg if you had test.wav and test.php. If someone searched for test.mp3, they would probably want test.wav not test.mp3
if(in_array($ext, $data)){
checkInData();
checkInImg();
checkInAudio();
checkInVideo();
checkInComp();
}
elseif(in_array($ext, $img)){
checkInImg();
checkInData();
checkInAudio();
checkInVideo();
checkInComp();
}
elseif(in_array($ext, $audio)){
checkInAudio();
checkInVideo();
checkInImg();
checkInData();
checkInComp();
}
elseif(in_array($ext, $video)){
checkInVideo();
checkInAudio();
checkInImg();
checkInData();
checkInComp();
}
elseif(in_array($ext, $comp)){
checkInComp();
checkInData();
checkInVideo();
checkInAudio();
checkInImg();
}
else{
checkInData();
checkInImg();
checkInAudio();
checkInVideo();
checkInComp();
}
print '
[b]404 - Not found.[/b]
<br style="height: 5px;">
[b]If you clicked a valid link, please notify the webmater[/b]
';
?>
You can get the download over at chrixel, its upped to mediafire so you don't need to register: http://chrixel.com/forums/index.php?...page__pid__917timtamboy63 Reviewed by timtamboy63 on . Smart404 Hey guys, I just finished coding my "smart" 404 script and I thought i'd release it. Release for www.chrixel.com (a awesome web coding and design forum) but I thought i'd post it here and hopefully get chrixel a bit of traffic :P Heres the contents of the readme in there because I really can't be bothered to type it up again ################################################################## Smart404 Script, created by timtamboy63 for released for www.chrixel.com Rating: 5
Need a Designer/Web Developer? Click Me
MSN: PM me for it.
Email(Preferred):timtamboy63@gmail.com
"Power Corrupts. Absolute Power Corrupts Absolutely"
-
23rd Jul 2010, 02:15 AM #2
Sponsored Links
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
themaPoster - post to forums and...
Version 5.40 released. Open older version (or...