note 56909 deleted from reserved.variables by felipe
| From: | felipe@php.net | Date: | Sun, 30 Dec 2007 18:22:46 +0000 |
| Subject: | note 56909 deleted from reserved.variables by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-134350@lists.php.net to get a copy of this message | ||
Note Submitter: jeromenelson at gmail dot com
----
You can take advantage of 404 error to an usable redirection using REQUEST_URI ...
For example the following program can retrieve the information for the 'search_string',
for a given URI: http://servername/profiles/search_string, even
though there's no such path.
Do the following steps..
Step 1: Edit Apache config: set
ErrorDocument 404 "/missing.php"
Step 2: Write the missing.php as follows ...
<?
$mainPath = "/profiles/"; // Example: http://servername/profiles/search_string
$mpLength = strlen( $mainPath );
$request_uri = $_SERVER['REQUEST_URI'];
if ( $mainPath != substr($request_uri,0,$mpLength) ) { // Check if the given URI is valid
echo "404 Page Not Found !";
exit();
}
$name = substr ($request_uri , $mpLength ) ; // Extract the string to be searched
echo "You have searched for the profile of Mr. $name";
/** Here you can write the code to retrieve and display
the $name's information from the database
*/
?>
Step 3: Now try http://servername/profiles/Jerry
(of course, there shouldn't be a file/folder in the server like
"DOCROOT/profiles/Jerry" )
output: You have searched for the profile of Mr. Jerry
God Bless You!