当必须从两个以上的嵌套文件夹重定向到页面时,php-header()不起作用

当必须从两个以上的嵌套文件夹重定向到页面时,php-header()不起作用,php,redirect,header,protection,Php,Redirect,Header,Protection,我有一个.php文件,在提交表单时调用它。通过在该文件中使用isset($_POST[“submit”]){}else{Header()},我试图阻止用户从浏览器键入指向该文件的直接URL。当我遇到这样的情况时,它工作得很好: if( isset($_POST["submit"])) { // some code } else { header("Location: ../../index.php");

我有一个.php文件,在提交表单时调用它。通过在该文件中使用
isset($_POST[“submit”]){}else{Header()}
,我试图阻止用户从浏览器键入指向该文件的直接URL。当我遇到这样的情况时,它工作得很好:

       if( isset($_POST["submit"])) {
            // some code
        } else {
            header("Location: ../../index.php");
            exit();
    ?>
表单提交.php文件的位置

root_folder/folder_level_1/folder_level_2/form_submitting.php
root_folder/folder_level_1/folder_level_2/folder_level_3/form_submitting.php
标题()重定向到的索引页的位置

root_folder/folder_level_1/index.php
root_folder/folder_level_one/index.php
表单提交.php的.php代码是:

<?php 
session_start();

    if(isset($_POST["submit"])) {
        // some code
    } else {
        header("Location: ../index.php");
        exit();
?>
<?php 
session_start();

    if(isset($_POST["submit"])) {
        // some code
    } else {
        header("Location: .../index.php");
        exit();
?>
标题()重定向到的索引页的位置

root_folder/folder_level_1/index.php
root_folder/folder_level_one/index.php
表单提交.php的.php代码是:

<?php 
session_start();

    if(isset($_POST["submit"])) {
        // some code
    } else {
        header("Location: ../index.php");
        exit();
?>
<?php 
session_start();

    if(isset($_POST["submit"])) {
        // some code
    } else {
        header("Location: .../index.php");
        exit();
?>
但它仍然不起作用。它显示我禁止访问将我重定向到
index.php

       if( isset($_POST["submit"])) {
            // some code
        } else {
            header("Location: ../../index.php");
            exit();
    ?>

如何解决这个问题?非常感谢您的帮助。

如果有,请忘记写信。它应该是
if(isset($\u POST['submit'])…
       if( isset($_POST["submit"])) {
            // some code
        } else {
            header("Location: ../../index.php");
            exit();
    ?>
如果要向上移动一个目录,则忘记了结束引号和../index.php

尝试,如果你想去2个文件夹

header("Location: ../../index.php");

你忘了写if。它应该是
if(isset($\u POST['submit'])…
       if( isset($_POST["submit"])) {
            // some code
        } else {
            header("Location: ../../index.php");
            exit();
    ?>
如果要向上移动一个目录,则忘记了结束引号和../index.php

尝试,如果你想去2个文件夹

header("Location: ../../index.php");

标题(“位置:…/index.php”);
..?点太多了,伙计…单点是当前目录。两个点是上一个目录。每个级别都必须用目录分隔符分隔。但最后一行可能会将您带到您想去的地方,或者将其发送到根目录。好的,一点
/
-相同的文件夹,两个点
。/
-上一个文件夹,以及如何准确地书写向上移动两个文件夹?@user3120612.././索引。php@SayedMohd Ali解决了我的问题。非常感谢!
header(“Location:…/index.php”);
..?点太多了,伙计…单点是当前目录。两个点是上一个目录。每个级别都必须用目录分隔符分隔。但最后一行可能会将您带到您想去的地方,或者将其发送到根目录。好的,一点
/
-相同的文件夹,两个点
。/
-上一个文件夹,以及如何准确地书写向上移动两个文件夹?@user3120612.././索引。php@SayedMohd Ali这解决了我的问题。非常感谢!忘了把它们放在示例中。我的实际脚本中有它。我更正了我问题的文本。@user3120612您也忘了头函数中的closign引号。如果您的index.php是o,您应该使用double../向上移动一个目录ne文件夹打开。@user3120612还检查您对index.php文件的权限。这也是一个打字错误。我也更正了。很抱歉,我弄乱了。忘记把它们放在示例中。我在实际脚本中有它。我更正了我问题的文本。@user3120612您也忘记了在头函数中使用closign引号。您应该使用double。。/如果index.php是一个文件夹,则向上移动一个目录。@user3120612还检查您对index.php文件的权限。这是一个拼写错误。我也更正了。很抱歉,我弄乱了。
       if( isset($_POST["submit"])) {
            // some code
        } else {
            header("Location: ../../index.php");
            exit();
    ?>