在 PHP 中向随机用户显示 html 内容

Displaying html content to random users in PHP

本文关键字:显示 html 内容 用户 随机 PHP      更新时间:2023-09-26

我正在尝试为在 php 中具有特定 id 的用户启用我的 Web 表单的输入元素,目前这里是动态 html 内容:

<input type="text" name="you" placeholder="only user with the following id can see this, sorry." disabled>

以下是仅为所选用户激活的代码:

 function chkboxClick(chkbox) {
        chkbox.nextSibling.nextSibling.disabled = !chkbox.checked;
    } // Checkbox appears asking user to check to enable input

我不是在专门选择一个用户,而是在尝试选择一个随机用户。基本上,数据库中有一个表或某种形式的代码,它随机选择一个用户并将"YoureTheOne"ID分配给激活上述代码的用户。如何创建此表/代码,将 id 随机分配给用户?

输入要显示文本区域的该用户的ID

假设

$array_id = [12,14,15,18,19,22,25];
if(in_array($current_user_id,$array_id)){
    <input type="text" name="you" value="your text">
} else {
    <input type="text" name="you" placeholder="only user with the following id can see this, sorry." disabled>
}