Ok, so I’ve written a script that will create a random number, check the database and if number exists in a userid row, it will recreate a new number and continue until it finds an available number…I started thinking though, if my site gets HUGE, wouldn’t that be a terrible thing it trying to randomly find numbers and possibly having to continuously repeat itself…is there a better way of doing this or is this the route to go?
The user ID is not a private number as it can be used to get to user profiles…its being setup like Facebook where the long string of numbers OR a username can go to the persons profile.
I assume you are (for whatever reason) trying to stop someone from visiting a page like
profile/<user_id>, and seeing thatuser_id= 100, then tryingprofile/101,profile/102, etc, etc.If that is the case, then you can use something like this (along with autoincrementing ids)
You would then have a route like
profile/c2ffd340ea3b71ca065e6add4143f36dIn your profile page, assuming the user_id was accessible in
user_id, you could simple do:And proceed like normal. When creating a link to someone’s profile page you would use something like
profile/<?php echo Crypt::encrypt($user->user_id); ?>