donglulong0877 2017-01-23 22:05
浏览 58
已采纳

当URL包含ID时,如何显示<div>?

I need to display certain content on the document when the URL contains that particular content's ID. Currently, the USER will go through a series of steps for a security check. At the end, a cookie will be placed on their system to avoid doing the security check in 30 days. Now, let's say that the cookie fails to go on the system or it fails to locate the cookie on the user's system, there has to be a notice so the user doesn't get confused on why they are getting another security check before 30 days. So far, this is what I got:

Places the cookie on the computer (setcookie.php):

<?php
$cookie_name = "securitycheck";
$cookie_value = "29610741351979104njnj23j52nx72d72n892ccr3179hd3";
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1 day
?>

Validates 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>

Finished page (checkfinished.php) [This is where I'm stuck on]:

<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>

- Now I need it to show the Div with the nocookieset id if the URL contains the id in there (such as http://example.com/example.php?nocookieset)

If it doesn't contain ?nocookieset in the URL, then it won't show the Div.

How can I make this happen?

  • 写回答

3条回答 默认 最新

  • duanruinong0619 2017-01-23 22:13
    关注

    Using JS:

    <script>
        if(location.search === "?nocookieset") document.getElementById("nocookieset").style.visibility="visible";
    </script>
    

    Version that supports more than one ID:

    <script>
        var supportedIds = ["nocookieset", "toomanycookiesset"];
        if(supportedIds.indexOf(location.search.substr(1))>-1) {
            document.getElementById(location.search.substr(1)).style.visibility="visible";
        } 
    </script>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答