标头('位置:..')不起作用 [英] header('location: ..') not working

查看:29
本文介绍了标头('位置:..')不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(1)我正在将我的网站上传到远程 Web 服务器.

(1)I'm in the process of uploading my website to a remote web server.

(2)网站的模板系统是通过向index.php

(2)The site's template system is set up in a way that all of the pages are formed by sending url-encoded get requests to index.php

(3)加载初始页面有效.此页面通过评估其表单的值来确定下一页的位置.

(3)Loading up the initial page works. This page determines the location of the next page by evaluating the value of its form.

(4)重定向到下一页是通过做一个:header('location: next_page')

(4)The redirection to the next page is performed by doing a: header('location: next_page')

(5)由于某种原因,没有执行重定向.代码如下所示:

(5)For some reason, the redirection is not performed. Here's what the code looks like:

$error = "";
if(isset($_POST['index_choice'])){
    $path_choice = isset($_POST['path']) ? $_POST['path'] : NULL;

    //echo $path_choice;
    //echo $page_inc;

    //nothing after this

    if($path_choice != null){

        if($form->is_connected()){

            //if($path_choice != "" || $path_choice != NULL){
                if($path_choice == "new"){

                    //header('location: /login.php');
                    //header('location: page/login');
                    header('location: /index.php?page=login');
                    exit();

                }
                else{

                    //header('location: /amend.php');
                    //header('location: page/amend');
                    header('location: /index.php?page=amend');
                    exit();
                }
            //}
            /**
            else{
                //destroy_session();
                $error = "You haven't selected a path. Please choose a path";
            }
             *
             */
        }
        else{
            //destroy_session();
            $error = "Problems with connecting to the database";
        }
    }else{
        //destroy_session();
        $error = "You have not indicated your choice";
    }

}

已解决

这是在代码中其他地方的 ?> 之后有一个空格的问题.在代码顶部放置以下命令后,我发现了这一点:

It was a matter of having a blank space after a ?> somewhere else in the code. This was revealed to me after placing the following commands at the top of the code:

 error_reporting(E_ALL); ini_set('display_errors', 'On'); 

我要感谢所有试图提供帮助的人.

I'd like to say thanks to all of the people that have tried to help.

推荐答案

看起来您在发送标头('location')之前将文本回显到浏览器.在执行 header() 之前,您不能将内容发送到浏览器,因为您的回声会强制发送标头.注释掉这些行,看看它是否有效:

Looks like you're echo-ing text to the browser before sending the header('location'). You can not send content to your browser before executing a header(), as your echo will force a header to be sent. Comment these lines out and see if it works:

// echo $path_choice;
// echo $page_inc;

现在您的标头将被发送,您将被重定向.

Now your header will be sent and you will be redirected.

这篇关于标头('位置:..')不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆