note 56909 added to reserved.variables
| From: | jeromenelson at gmail dot com | Date: | Mon, 19 Sep 2005 10:56:54 +0000 |
| Subject: | note 56909 added to reserved.variables | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-95402@lists.php.net to get a copy of this message | ||
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!
----
Manual Page -- http://www.php.net/manual/en/reserved.variables.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+56909
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56909&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56909&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56909&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56909&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56909&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+56909&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56909&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+56909&report=yes
Search -- http://master.php.net/manage/user-notes.php