我在解决这个问题时遇到了一些麻烦。用户登录及其 ip $_SERVER['REMOTE_ADDR']
将从具有多个 ip 的多行数据库中 checkin 。
id(Primary) name ip
1 abc 127.0.0.1,999.45.67.89
2 xyz 192.168.0.1,108.34.65.78
现在,如果我登录,我的 IP 127.0.0.1 出现在第一行。我有一个可以获取上表的表单。
<?php
$sql="select * from center_listt";
$res=mysql_query($sql);
if(!$res) {
die('could not connect'.mysql_error());
} ?>
<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<table border="1">
<table>
<tr>
<th>ID</th>
<th>Name</th>
<th>IP Details</th>
</tr>
<?php while($row=mysql_fetch_assoc($res))
{
?>
<tr >
<td><?php echo $row['idr']; ?></td>
<td><?php echo $row['name']; ?></td>
<td><textarea rows="4" cols="40" name="ip_details[]"><?php echo $row['ipdetails']; ?></textarea><br/></td>
</tr>
因此,如果我的 IP 在数据库的第一行或 fetched-textarea 中找到,我只能在该文本区域中进行编辑。其他文本区域将被禁用。我不知道,只能检查用户 IP,然后循环遍历每个文本区域来自数据库的行以及IP是否发现可能有一个JavaScript来启用禁用?
最佳答案
你可以使用
$sql="select * from center_listt WHERE ip LIKE '%" + $_SERVER['REMOTE_ADDR'] + "%'";
选择包含当前用户 IP 地址的所有行。
最诚挚的问候,
内博伊萨
关于php - 如何从数据库检查用户IP并启用/禁用表单文本区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24138577/