Free Programming E-Books
Free download ebooks on computer and programming

Free Ebook Computer Programming

Free Ebook Computer Programming :
PHP & MySQL Conference.pdf
Publisher :
Unknown
Pages :63
Format :pdf
Size :0.5 MB
Upload date :09-25-05

Table of content

Coming soon

Other HOT and Free ebooks!!

Coming Soon

Free Ebook PHP & MySQL Programming : PHP & MySQL Conference.pdf

ErroDocument

Apache's ErrorDocument directive can come in handy. For example, this line in your Apache configuration file:

ErrorDocument 404 /error.php
Can be used to redirect all 404 errors to a PHP script. The following server variables are of interest:
  1. $REDIRECT_ERROR_NOTES - File does not exist: /docroot/bogus
  2. $REDIRECT_REQUEST_METHOD - GET
  3. $REDIRECT_STATUS - 404
  4. $REDIRECT_URL - /docroot/bogus

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
  1. Search for closest matching valid URL and redirect
  2. Use attempted url text as a DB keyword lookup
  3. Funky caching
........more

Download free ebook : Rasmus_Lerdoff--PHP_&_MySQL_Conference.pdf
Free ebook download -- PHP & MySQL Conference Result


Funky Caching

An interesting way to handle caching is to have all 404's redirected to a PHP script.
ErrorDocument 404 /generate.php
Then 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.

Top