Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8889121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:11:06+00:00 2026-06-14T22:11:06+00:00

Ok, so I’ve written a script that will create a random number, check the

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T22:11:07+00:00Added an answer on June 14, 2026 at 10:11 pm

    I assume you are (for whatever reason) trying to stop someone from visiting a page like

    profile/<user_id>, and seeing that user_id = 100, then trying profile/101, profile/102, etc, etc.

    If that is the case, then you can use something like this (along with autoincrementing ids)

    class Crypt {
    
        public static function encrypt($data) {
    
            $config = LoadSomeConfig();
    
            // open the module to be used.  There are several listed at http://www.php.net/manual/en/mcrypt.ciphers.php     
            $mod = mcrypt_module_open($config->cipher, '', $config->mode, '');
    
            // use config set initialization vector.  We will use a constant here as we do not want to include this for decryption
            if (isset($config->vector)) {
                $iv = $config->vector;
            } else {
                die("NO IV SET!");
            }
    
            $key_size = mcrypt_enc_get_key_size($mod);
            $key = substr($config->key, 0, $key_size);
            mcrypt_generic_init($mod, $key, $iv);
    
            // Do the encryption using the cipher module defined
            $encrypted = mcrypt_generic($mod, $data);
    
            // cleanup
            mcrypt_generic_deinit($mod);
            mcrypt_module_close($mod);
    
            // Changed the output based on the config encoding value.  Currently supported values, base64 and hex.
            switch ($config->encoding) {
                case "base64":
                    $encrypted = base64_encode($encrypted);
                    break;
                case "hex":
                    $encrypted = bin2hex($encrypted);
                    break;
                default:
                    break;
            }
            return $encrypted;
        }
    
        public static function decrypt($data){
    
            if (empty($data)) {
                return '';
            }
    
            // config options set include the cipher, mode and secret key
            $config = LoadSomeConfig(); 
    
            // Change encrypted data base to binary based on the encoding mechanism used to generate the data
            switch ($config->encoding) {
                case "base64":
                    $data = base64_decode($data);
                    break;
                case "hex":
                    $data = pack("H*", $data);
                    break;
                default:
                    break;
            }
    
    
            if (isset($config->vector)) {
                $iv = $config->vector;
            } else {
                die("NO IV SET!");
            }
    
            $mod = mcrypt_module_open($config->cipher, '', $config->mode, '');
            $key_size = mcrypt_enc_get_key_size($mod);
            // max key size is 448 bits
            $key = substr($config->key, 0, $key_size);
            mcrypt_generic_init($mod, $key, $iv);
    
            // decrypt the data
            $decrypted = mdecrypt_generic($mod, $data);
    
            // cleanup
            mcrypt_generic_deinit($mod);
            mcrypt_module_close($mod);
    
            return trim($decrypted);
        }
    }
    

    You would then have a route like profile/c2ffd340ea3b71ca065e6add4143f36d

    In your profile page, assuming the user_id was accessible in user_id, you could simple do:

    $user_id = Crypt::decrypt($user_id);
    

    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); ?>

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small JavaScript validation script that validates inputs based on Regex. I
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.