I would create another column in the database called "slug" and make it a unique row. Now, adding a new entry, I would generate a slug for this.
I found an example for a bullet creation function as an answer to this question: PHP function to create a pool (URL string)
The slugify function provided in the answer to this question does not check if a value exists in your database. You have to do it yourself and add a suffix like "-1" if slug already exists.
If you did all this, your data should look something like this:
Table Users User_id First_name Last_name Slug 1 John Smith john-smith 2 John Smith john-smith-1 3 Kia Dull kia-dull
The following steps should be fairly easy.
This will be the ability to create links:
<a href="<?php echo $row['Slug'] ?>"><?php echo $row['First_name'] ?> <?php echo $row['Last_name'] ?></a>
The .htaccess file should be the same as yours already ...
RewriteEngine on RewriteBase / RewriteRule ^(.*)$ profile.php?uid=$1 [L]
And you just need to query the table for a value like $ _GET ['uid'] in the profile.php file. Now I renamed the uid parameter to slug because it is no longer an ID, but you can easily get the identifier by requesting it after the bullet.
The advantages of this solution:
- Easy to debug. Slug is what you can find in a 1: 1 database. If you have a URL, you can tell without knowing which user it is.
- According. Even if you delete the line with id = 1, the line id = 2 will still have the pool "john-smith-1"
FYI:
Slug is the part of the URL that identifies the page using human-readable keywords. http://en.wikipedia.org/wiki/Clean_URL#Slug
source share