标题(“位置:..')不工作 [英] header('location: ..') not working

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

问题描述

(1)我在上传自己的网站到一个远程Web服务器的过程。

(2)该网站的模板系统是建立在所有的页面都通过发送URL-CN codeD GET请求的index.php

(3)装载了初始页面的作品。当前页通过评估其形式的值决定下一个页面的位置。

头('位置:next_page')

(4)重定向到下一个页面做一个执行

(5)由于某种原因,不进行重定向。这里的code样子:

  $错误=;
如果(使用isset($ _ POST ['index_choice'])){
    $ path_choice =使用isset($ _ POST ['路径'])? $ _ POST ['路径']:NULL;    //回声$ path_choice;
    //回声$ page_inc;    //在此之后什么    如果($ path_choice!= NULL){        如果($形式 - > is_connected()){            //如果($ path_choice!=|| $ path_choice!= NULL){
                如果($ path_choice ==新){                    //头('位置:/login.php');
                    //头('位置:页/登录');
                    头('位置:/index.php?page=login');
                    出口();                }
                其他{                    //头('位置:/amend.php');
                    //头('位置:页/修改');
                    头('位置:/index.php?page=amend');
                    出口();
                }
            //}
            / **
            其他{
                // destroy_session();
                $错误=您没有选择请选择一个路径的路径。
            }
             *
             * /
        }
        其他{
            // destroy_session();
            $错误=问题与连接到数据库;
        }
    }其他{
        // destroy_session();
        $错误=您没有标明你的选择;
    }}

解决

它是一种具有&GT后一片空白的问题; 其他地方在code。这是把下面的命令在code后上方向我透露:

 的error_reporting(E_ALL);的ini_set('display_errors设置','开');

我想感谢说所有那些​​试图帮助的人。


解决方案

你看上去回声ING文本浏览器发送头('位置')之前。
执行一个头()之前,您无法将内容发送到浏览器,因为你的回音将强制发送一个头。从这些评论线和看看它是否工作:

  //回声$ path_choice;
//回声$ page_inc;

现在你的头将被发送,你会被重定向。

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

(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)Loading up the initial page works. This page determines the location of the next page by evaluating the value of its form.

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

(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";
    }

}

SOLVED

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.

解决方案

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天全站免登陆