Free Programming Books
Free download ebooks on computer and programming | |||
Free Ebook Computer ProgrammingFree Ebook Computer Programming : PHP & MySQL Conference.pdf Publisher : Unknown Pages :63 Format :pdf Size :0.5 MB Upload date :09-25-05 Table of contentComing soon Other HOT and Free ebooks!!Coming Soon Free Ebook PHP & MySQL Programming : PHP & MySQL Conference.pdfErroDocumentApache's ErrorDocument directive can come in handy. For example, this line in your Apache configuration file: ErrorDocument 404 /error.phpCan be used to redirect all 404 errors to a PHP script. The following server variables are of interest:
Don't forget to send a 404 status if you choose not to redirect to a real page. <? Header('HTTP/1.0 404 Not Found'); ?>
Interesting uses
Download free ebook : Rasmus_Lerdoff--PHP_&_MySQL_Conference.pdf
Previous free ebook Previous part of free ebook Next Free ebook Next part of free ebook Funky CachingAn interesting way to handle caching is to have all 404's redirected to a PHP script.ErrorDocument 404 /generate.phpThen in your generate.php script use the contents of $REDIRECT_URI to determine which URL the person was trying to get to. In your database you would then have fields linking content to the URL they affect and from that you should be able to generate the page. Then in your generate.php script do something like: <?php
$s = $REDIRECT_URI;
$d = $DOCUMENT_ROOT;
// determine requested uri
$uri = substr($s, strpos($s,$d) + strlen($d) + 1);
ob_start(); // Start buffering output
// ... code to fetch and output content from DB ...
$data = ob_get_contents();
$fp = fopen("$DOCUMENT_ROOT/$uri",'w');
fputs($fp,$data);
fclose($fp);
ob_end_flush(); // Flush and turn off buffering
?>
So, the way it works, when a request comes in for a page that doesn't exist, generate.php checks the
database and determines if it should actually exist and if so it will create it and respond with this generated data. The next request for that same URL will get the generated page directly. So in order to refresh your cache you simply have to delete the files.
| |||