好了,所以我想生成一个随机值,使用random_bytes,告诉用户他的唯一的ID,然后插入到数据库中。生成一个随机值,并插入到数据库中的PHP
我使用isset,所以我尝试做$ id = bin2hex(random_bytes(16)),但当用户单击注册按钮时它会生成另一个ID,这意味着他保存的值不是插入到数据库。
基本上,这对他来说是生成和他需要以登录(作为用户名),以节省一个随机标识符。
谢谢!
我知道这件事情做的isset,因为值用户的帖子后生成的形式,但我想告诉他不要在还没有产生的东西。不知道该怎么做。
<?php
if (isset($_POST['regbutton'])) {
$username = bin2hex(random_bytes(16));
$password = ($_POST['password']);
$repeatpw = ($_POST['repeatpw']);
// blah blah validations
// executes a database query and insets the $username variable into the db
HTML - <input type="text" class="form-control" name="username" value="<?php echo $username; ?>">
为什么一定是随机的?顺序有问题吗? –
请向我们展示您的代码。如果我们不知道你在做什么,我们就无能为力。 – Chris
我不太喜欢用户知道有多少人的想法。 – Nick