Auto incrementing the ID value through mysql's auto increment may leak some sensitive data.
For example, the user_id of the user table is auto-incremented, and the id value displayed in the URL may reveal the real number of users of the website.
The following code implements a simple number generator through PHP and redis' incrby. The code is as follows:
function get_id($type, $server_ip, $server_port, $key) { $init_num = 0; $redis= new Redis(); $redis->connect($server_ip, $server_port); $var = $redis->exists($key); if($var == 0) { $redis->set($key,$init_num); } $incr_num = rand(1,50); //增量为随机数 $var = $redis->incrby($key, $incr_num); $redis->close(); return $var; }
The above introduces the redis implementation of the number dispatcher, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.