Location: PHPKode > scripts > 404.php > gist146055-09d5e3b49a8d4873f483e5c87971a1998f387f81/404.php
<?php
//
// code licensed http://creativecommons.org/licenses/by-nc/3.0/
// plus, one rule. a link to http://dennyhalim.com from wherever this code used
//
// first of all, add this line (without //) to .htaccess:
// ErrorDocument 404 /404.php
//
// you dont need to edit anything here
// unless you want to change the looks & feel to match your website you can edit the html at the bottom
//
ob_start();
$browser = $_SERVER['HTTP_USER_AGENT'];
$msie = 'Mozilla/4.0 (compatible; MSIE ';
$lotsbrowsers = 'Mozilla/';
//$cek = strpos($browser,$msie);
//nowadays... too much toolbars/browsers/etc hijacking 404 error pages. let give them all soft-404
$cek = strpos($browser,$lotsbrowsers);

// now that we lie to msie that this is not 404 error page,
// it's safe to remove all the too much useless comments at the html section
if ($cek === false) {
header("HTTP/1.1 404 Not Found");
header("Status: 404 Not Found");
} else {
header("HTTP/1.1 200 OK");
header("Status: 200 OK");
}
header('X-Powered-By: http://wiki.dennyhalim.com/404-php');
?>
<!--// 
404.php is a better, friendly solution to 404 not found page
(c) 2007 Denny Halim ST S.Kom ; Polaris Network Indonesia
http://www.DennyHalim.com - http://www.PolarisNetwork.com
http://wiki.dennyhalim.com/404-php
http://creativecommons.org/licenses/by-nc/3.0/
//-->
<?php
// you can also override $domain = 'www.yourdomainname.com';
// especially if the server http host return wrong answer like 127.0.0.1 or localhost
$domain =  str_replace('www.', '', $_SERVER['HTTP_HOST']);
//$domain =  'youdomainname.com';
$url = $_SERVER['REQUEST_URI'];

$path = parse_url($url, PHP_URL_PATH);
$path_parts= pathinfo($path);
$path = $path_parts['dirname'];
$path= urldecode(stripslashes($path));
$namafile = $path_parts['filename'];

$pisah = array("_", "/", "-", "+");
$path= str_replace($pisah, " ", $path);
$namafile = str_replace($pisah, " ", $namafile);
$dicari = $path . " " .  $namafile;

// choose either ajaxsearch or standard search form
// or, put up your own custom search
//$mencari = 'http://ajaxsearch.jgate.de/?domain=' . $domain . '&dicari=' . $dicari;
$mencari = 'http://cari.jgate.de/?big=1&status=404&domain=' . $domain . '&dicari=' . $dicari;

?>

<html>
<head>

<!--// 

you can put up some css styling here 

you can edit the html code below to suite your website looks & feel
you must leave the link back to http://wiki.dennyhalim.com/404-php

//-->

<META NAME="ROBOTS" CONTENT="NOINDEX, FOLLOW">
<title>Status: 404 Not Found</title>
</head>
<body>


<h2>Status: 404 Not Found</h2>
<h4>The Page does not exist.</h4>
<p>

<!--// you can also add more links or menu or sitemap etc... //-->

<p>Suggestions:</p>
<ul>
<li>try <a href="http://www.<?php echo $domain; ?>">www.<?php echo $domain; ?></a> or <a href="http://<?php echo $domain; ?>"><?php echo $domain; ?></a> </li>
<li>check for typos. maybe the link mistyped. try removing any spaces in the url. </li>
<li>find a copy at <a href="http://www.google.com/search?q=cache:<?php echo $_SERVER['HTTP_HOST']; echo $url; ?>">Google</a> or <a href="http://web.archive.org/web/*/<?php echo $_SERVER['HTTP_HOST']; echo $url; ?>">Wayback Machine</a></li>
<li>go <a href="javascript:history.back()">back</a> where you came from </li>
<li>search</li>
</ul>
<hr>

<div id="content">
<p>Javascript is loading Your <a rel="nofollow" href="<?php echo $mencari; ?>">search on <?php echo $domain; ?> for <?php echo $dicari; ?></a><br/>
if you disabled javascript, it will never loaded.</p>
<p><a href="http://wiki.dennyhalim.com/404-php" title="better, friendly custom 404 error page">get your own 404.php</a></p>
</div>

<!--// let's do some cool ajax search for our visitors  //-->

    <script src="http://www.google.com/jsapi"></script>
    <script type="text/javascript">
    google.load('search', '1');
    function OnLoad() {
      var customSearchControl = new google.search.CustomSearchControl('003127643427034444210:vcvoo5yqjhg');
      customSearchControl.draw('content');
      customSearchControl.execute('<?php echo $dicari; ?> site:<?php echo $domain; ?>');
    }
    google.setOnLoadCallback(OnLoad);
    </script>
<noscript>
<iframe src="<?php echo $mencari; ?>" width="100%" height="2000" frameborder="0" scrolling="no"></iframe>
<p><a href="http://wiki.dennyhalim.com/404-php" title="better, friendly custom 404 error page">get your own 404.php</a></p>
</noscript>
<NOFRAMES>
<a rel="nofollow" href="<?php echo $mencari; ?>">click here to search <?php echo $domain; ?> for <?php echo $dicari; ?></a>
<p><a href="http://wiki.dennyhalim.com/404-php" title="better, friendly custom 404 error page">get your own 404.php</a></p>
</NOFRAMES>
</body>
</html>

<?php ob_end_flush(); 
Return current item: 404.php