Php 如何从多个ID中匹配一个ID';s
我在下面有一个脚本,它扫描允许查看帖子的用户。如何更新它,使其与查看人员的ID与存储在字段中的ID相匹配。如果它匹配,它工作,否则它不工作。存储的条目类似于99394david、324234smith、34343jane。所以我的脚本与它不匹配Php 如何从多个ID中匹配一个ID';s,php,security,matching,verification,Php,Security,Matching,Verification,我在下面有一个脚本,它扫描允许查看帖子的用户。如何更新它,使其与查看人员的ID与存储在字段中的ID相匹配。如果它匹配,它工作,否则它不工作。存储的条目类似于99394david、324234smith、34343jane。所以我的脚本与它不匹配 $kit = mysql_real_escape_string($_GET['id']); $sql="SELECT `Who_can_see` from `posts` where `post_id` = '$kit'"; $re
$kit = mysql_real_escape_string($_GET['id']);
$sql="SELECT `Who_can_see` from `posts` where `post_id` = '$kit'";
$result=mysql_query($sql);
$query = mysql_query($sql) or die ("Error: ".mysql_error());
if ($result == "")
{
echo "";
}
echo "";
$rows = mysql_num_rows($result);
if($rows == 0)
{
print("");
}
elseif($rows > 0)
{
while($row = mysql_fetch_array($query))
{
$userallowed = htmlspecialchars($row['who_can_see']);
}
}
//$personid is drawn from the database. its the id of the
person viewing the link.
if ( $userallowed == $personid ) {
echo("allowed");
} else {
echo("not allowed");
die();
}
?>
我只想将
$personid
添加到查询中(尽管我怀疑您是如何准确填写帖子
表的……):
如果结果包含一行,则允许用户查看帖子
顺便说一句,我还建议使用预先准备好的语句来避免任何潜在的sql注入问题
编辑:基于可以看到的人可以包含逗号分隔的条目列表,您可以使用原始脚本,只需更改匹配方式,例如使用
谢谢那没用。我用的是转义字符串,应该够了,不是吗?@ariel是的,够了。作为一个有效的例子,这两个值(Who_-can_-see
和$personid
)到底是什么样的?Who_-can_-see可能拥有所有人,只有我,也可能是像99394david这样的一个人,或者像99394david这样的多个人,3242344smith,34343jane,我相信我需要添加一个结束语}。我这样做了,但尽管它不会在屏幕上显示任何内容…@ariel你只需要替换那一行,它下面的那一行只是为了清楚地标记在哪个部分。无论如何,你能发布var\u dump($userallowed)
和var\u dump($personid)
的结果吗?
$sql="SELECT `Who_can_see` from `posts`
where `post_id` = '$kit'
AND `Who_can_see` = '$personid'";
if ( stripos($userallowed, $personid) !== false ) {
// $personid is found in $userallowed
echo("allowed");
} else {
echo("not allowed");
die();
}