【发布时间】:2018-01-21 19:56:48
【问题描述】:
我正在尝试在 IF 和 ELSE 语句中传递 URL 参数。这就是只有链接而没有参数的初始代码的样子:
<?php
if ($row_checklist_finding_final['item_class'] == "Major")
{
echo '<a href="UserNCR.php">Go to NCR</a>';
}
else
{
echo '<a href="UserOFI.php">Go to OFI</a>';
}
?>
通常当我尝试传递 URL 参数时,我使用此代码(这是没有 if 和 else 语句:
<a href="UserNCR.php?item_id=<?php echo $row_checklist_finding_final['item_id']; ?>">
Go to NCR
</a>
所以我所做的是,我使用通常的方式将参数放入链接中,如下所示。
参数名称为item_id,等于值$row_checklist_finding_final['item_id']
<?php
if ($row_checklist_finding_final['item_class'] == "Major")
{
<a href="UserNCR.php?item_id=<?php echo $row_checklist_finding_final['item_id']; ?>">Go to NCR</a>
}
else
{
'<a href="UserOFI.php">Go to OFI</a>';
}
?>
我还尝试像这样删除多余的<?php ?>:
<?php
if ($row_checklist_finding_final['item_class'] == "Major")
{
<a href="UserNCR.php?item_id= echo $row_checklist_finding_final['item_id'];">Go to NCR</a>
}
else
{
'<a href="UserOFI.php">Go to OFI</a>';
}
?>
但是还是有错误。 我使用了错误的语法吗? 如何在 IF 和 ELSE 语句中传递 URL 参数?
【问题讨论】:
-
该样本可能容易受到 HTML 注入/cross-site scripting 的攻击,并且在某些情况下可能会产生无效的 HTML。见“How to prevent XSS with HTML/PHP?”
标签: php if-statement parameters url-parameters