To use the URL domain.com/ccroipr/201801101515569979
for a user profile, you need to implement the following two steps:
Create a php file called ccroipr.php
on your site, that contains code to analyse the request's URL.
This can be accomplished, by using the PHP global $_SERVER
variable in PHP. It contains a field named 'REQUEST_URI'
that stores the path that was used to access the given file. So for the URL domain.com/ccroipr/201801101515569979
the variable $_SERVER['REQUEST_URI']
holds the value ccroipr/201801101515569979
. This can be used to extract the suer id:
$requestParts = explode('/', strstr($_SERVER['REQUEST_URI'] . '?', '?', TRUE));
$userId = '';
if (count($requestParts) > 1) {
$userId = $requestParts[1];
}
if ($userId === '') {
// Redirect to login page, generate a new ID or show an error.
die();
}
// Call database and filter for the $userId value to retrieve all userspecific data
// Generate the specific HTML
The function strstr($path, '?', TRUE)
cuts off all the GET parameters from the requested path. You can still access them through the $_GET
variable though. A question mark is added to the original path to make sure the function still acts like expected in case no such parameters were submitted.
The function explode('/', $url)
then separates all parts of the path that are separated by slashes, so each part can be analysed for itself.
The condition if (count($requestParts) > 1)
checks, if the path part for the user id was submitted in the given URL. If it was, it is saved in the $userId
variable. Keep in mind though, that there still might have been submitted an empty string for it. This will happen if someone calls domain.com/ccroipr/
for example.
The condition if ($userId === '')
then verifies, if a user id was really submitted.
Modify your .htaccess file to allow requests that omit the .php ending.
The way to accomplish that is best described in this question: How to execute a PHP web page without the .php extension in the URL?