当 URL 包含特定内容的 ID 时,我需要在文档中显示特定内容。目前,用户将通过一系列安全检查步骤。最后,cookie 将被放置在他们的系统上,以避免在 30 天内进行安全检查。现在,假设 cookie 无法在系统上运行或无法在用户系统上找到 cookie,必须有一个通知,这样用户就不会对为什么他们在 30 天前进行另一次安全检查感到困惑.到目前为止,这是我得到的:
将 cookie 放在计算机上 (setcookie.php):
<?php
$cookie_name = "securitycheck";
$cookie_value = "29610741351979104njnj23j52nx72d72n892ccr3179hd3";
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1 day
?>
验证 cookie (checkcookievalidation.php):
<head>
<?php
$cookie_name = "securitycheck";
?>
</head>
<body>
<?php
if(!isset($_COOKIE[$cookie_name])) {
echo "Cookie named '" . $cookie_name . "' is not set! Internal Error!";
header( 'Location: checkfinished.php?nocookieset' ) ;
} else {
echo "Cookie '" . $cookie_name . "' is set!<br>";
header("Location: checkfinished.php");
}
?>
</body>
完成页面 (checkfinished.php) [这是我卡住的地方]:
<div id="nocookieset" style="visibility: visible;" align="center"><h3>Although the check did complete with errors. We were unable to set the cookie due to an internal server error. Please contact the web team about this if the issue continues.</h3></div>
- 现在,如果 URL 中包含 id (例如 http://example.com/example.php?nocookieset )
,我需要它显示带有 nocookieset id 的 Div如果 URL 中不包含 ?nocookieset
,则不会显示 Div。
我怎样才能做到这一点?
最佳答案
最好的方法是在 PHP 条件中注入(inject) HTML 内容:
<?php
if(isset($_GET['nocookieset'])) {
?>
<div id="nocookieset">
</div>
<?php
/* Don't forget to close the condition logic! */
}
?>
这样 nocookieset
DIV 只会在设置了 GET 变量时输出到页面:)
希望对您有所帮助! :)
关于javascript - 当 URL 包含 ID 时如何显示 <div>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41816542/