【问题标题】:header location not working but stuck in page标题位置不起作用但卡在页面中
【发布时间】:2013-07-30 09:50:15
【问题描述】:

所以我有一个按钮

<input type="button" value="add" onclick="document.location.href='add.php?myUcode=<?=$row['ucode'];?>'" />

到另一个页面(我们称之为 Page1)。在 Page1 中,我想向 $_SESSION['employees'] 添加一个值,然后将其重定向回 home.php。但是当我单击该按钮时,它会卡在 add.php 中。在我调用 Header 方法之前没有回声或空格。现在我不知道我的代码有什么问题:

<?php
session_start();
if ($_POST['tambah_ucode']) {
if (isset($_SESSION['jum_petugas'])) {
    $_SESSION['jum_petugas'] = 1;
    $ctr = $_SESSION['jum_petugas'];
} else {
    $ctr = $_SESSION['jum_petugas'];
    $ctr++;
    $_SESSION['jum_petugas'] = $ctr;
}
$_SESSION['ucode_petugas'][$ctr] = $_POST['tambah_ucode'];
header('Location: localhost/hrm2.1/lembur_add.php');
}
?>

【问题讨论】:

  • 试试这样的:header('Location: lembur_add.php');
  • @SureshKamrushi 仍然不起作用...
  • 我重新阅读了以前的页面,发现我意识到变量 'tambah_ucode' 是在 URL 中传递的,所以我应该使用 $_GET 而不是 $_POST.. 它现在可以工作了。多谢你们。如何将此问题设置为“已回答”或其他内容?

标签: php header location


【解决方案1】:

试试这个,

header('Location: lembur_add.php');
exit;

header('Location: http://localhost/hrm2.1/lembur_add.php');
exit;

【讨论】:

    【解决方案2】:
    header('location:localhost/hrm2.1/lembur_add.php')
    

    没有空格

    【讨论】:

    • 这毫无意义。
    【解决方案3】:

    试试下面的

    header('Location:http://localhost/hrm2.1/lembur_add.php');

    【讨论】:

      【解决方案4】:

      用 header(...) 代替,试试

      echo "<script type='text/javascript'> document.location = 'yourLocation'; </script>";
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-08-22
        • 1970-01-01
        • 2017-11-04
        • 2015-07-31
        • 1970-01-01
        相关资源
        最近更新 更多