【问题标题】:How to have a redirect using header(location: url) in php when click on a <a>text</a>?单击<a>文本</a>时如何在php中使用标头(位置:url)进行重定向?
【发布时间】:2017-02-11 22:04:27
【问题描述】:

我想使用它,因为我必须维护一个会话。 我尝试过这种方式,但是打开页面时该功能立即执行:

 <a onclick="myfunction();">text</a>

功能:

function myfunction()
{
  <?php
       header("location: page.php");
       exit;
  ?>
}

我也尝试过使用表单和按钮,但不起作用。

【问题讨论】:

    标签: php html session


    【解决方案1】:

    HTML

    <a href="redirect.php">text</a>
    

    redirect.php

    <?php
       session_start();
       if($_SESSION['smth']){
           header("location: page.php");
       } else {
          // to do what you want
       }
    ?>
    

    【讨论】:

    • 我试过了。这样 page.php 中的 $_SESSION 不起作用
    • 已发布部分源页面
    猜你喜欢
    • 2012-08-03
    • 2020-03-26
    • 2019-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多