代码之家  ›  专栏  ›  技术社区  ›  helloandre

保护没有标题的网页

  •  3
  • helloandre  · 技术社区  · 17 年前

    我刚刚读到这个 article on tdwtf.com

    理想情况下,我希望取代

    if (!$something_important) header("Location: somehereharmless.php");
    

    8 回复  |  直到 17 年前
        1
  •  7
  •   Alekc    17 年前

    if (!$something_important) {
      header("Location: somehereharmless.php");
      exit();
    }
    

    即使它是机器人,所以它不尊重位置,你也会调用一个出口,这样执行流无论如何都会停止,所以没有坏处

        2
  •  4
  •   Bart S.    17 年前

    <?php
    function redirect($url)
    {
        header('Location: ' . $url);
        exit('<a href="' . $url . '">Redirecting you to: ' . $url . '</a>');
    }
    
    redirect('somepage.php');
    ?>
    

    这样人们就无法绕过重定向,并且知道他们应该被重定向。


    使用 POST GET <img src="http://www.example.org/action.php?do=SetAsAdmin&userid=MyUserId" /> ).

        3
  •  2
  •   Paul Whelan    17 年前

    Idempotent意味着多次执行同一请求与执行一次具有相同的效果。

        4
  •  2
  •   David Z    17 年前

    if (user_is_authorized()) {
        // restricted code here
    }
    

    if (!user_is_authorized()) {
        // send headers or whatever if you want
        exit();
    }
    // restricted code here
    

        5
  •  1
  •   soulmerge    17 年前

    exit; header();

        6
  •  1
  •   Strae    17 年前
    if (!$something_important) {
      header("Location: somehereharmless.php");
      //close all your db connections and other stuff you need to end..parhaps calling a function?
      die("If the redirect doesnt start in 3 seconds, please <a href=\"somehereharmless.php\">click here</a>");
    }
    
        7
  •  1
  •   SchizoDuckie    17 年前

    <?php
    die($errormessage);
    

        8
  •  0
  •   Ólafur Waage    17 年前

    if($foo && $bar)
    {
        header("Location: somehereharmless.php");
    }
    
    if($foo && $baz)
    {
        header("Location: someotherplace.php");
    }