标头('Location:')不重定向 [英] header('Location:') not redirecting

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

问题描述

我有一个登录页面,该页面检查usernamepassword,如果用户提供的凭据匹配,它将设置会话并重定向用户,它可以在我的godadd托管帐户上工作,但是现在我有了转移了我的托管服务,突然它停止了工作,下面是代码

I have a login page which checks the username and the password and if the credentials provided by the user matches it sets the session and redirects the user, it works on my godadd hosting account but now i have shifted my hosting and suddenly it has stopped working, following is the code

if (count($result) > 0)
            {               
                $row= mysql_fetch_array($result);
                $userID = $row['userID'];               
                $firstName = $row['FirstName'];         

                $isActive = $row['IsActive'];

                if ($isActive == '1')
                {

                    $_SESSION['user'] = $firstName;     
                    //var_dump($firstName); //it gives me the right username                
                    //echo" - here";  //this also gets echoed
                    header("Location: http://google.com/"); //it just dies silently
                    exit;
                }

请帮助我找出我做错了什么地方

please help me find out where i went wrong

推荐答案

您需要确保在header标记之前不输出任何内容.由于它以前工作过,所以我认为在调用标头之前您没有回显任何东西是没有错误的,并且由于您没有看到输出,因此我假设它正在输出空白.在某些地方,某些空格和/或不可见字符可以潜入文件中:

You need to make sure you don't output anything before the header tag. Since it was working before, I assume it's not an error where you are echo'n stuff before the call to header, and since you see no output, I assume it is outputting white-space. There are a few places where some whitespace and/or invisible characters can sneak into a file:

将光标放在打开PHP标记(<? or <?php)之前,并按几次退格键,然后按Delete键删除<,然后重新键入<.这样可以确保在您的标题之前没有向浏览器输出任何不可见的字符.

Put the cursor before your opening PHP tag (<? or <?php) and hit backspace a few times, then hit delete to delete the < and then retype the <. That will make sure there are no invisible characters being output to the browser before your headers.

然后遍历该文件包含的所有文件,并执行相同的操作,并删除该文件末尾的所有?>.如果这些文件包含其他文件,请在其上重复此操作.

Then go through any files that are included by that file, and do the same thing, as well as delete any ?> that you have at the end of the file. If those files include any othe files repeat this on them.

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

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