Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 无法重定向到html页面_Php_Html - Fatal编程技术网

Php 无法重定向到html页面

Php 无法重定向到html页面,php,html,Php,Html,我的问题是在我成功登录后,它并没有重定向到我应该去的页面 另外,我使用的是apache服务器 下面是我认为需要修复的PHP部分 if($count==1){ // Register $Username, $Password and redirect to file "login_success.php" session_register("Username"); session_register("Password"); echo "Correct Usernam

我的问题是在我成功登录后,它并没有重定向到我应该去的页面

另外,我使用的是apache服务器

下面是我认为需要修复的PHP部分

if($count==1){
    // Register $Username, $Password and redirect to file "login_success.php"
    session_register("Username");
    session_register("Password");
    echo "Correct Username & Password";

    header("location:$http://localhost/.../contacts.html");
    }
    else {
    echo "Wrong Username or Password";
    header("location:../php/error.php");
    }
利用

标题(“位置:$http://localhost/.../contacts.html");

我得到403个禁止的错误。。 此错误未出现在网页上,而是出现在firebug上

如果我替换为

标题('位置:http://localhost/.../contacts.html' ) ;

标题(“位置:../../contacts.html”)

标题('Location:../../contacts.html')

它没有给我任何错误,但它在firebug中的唯一响应是显示contacts.html的html代码,而不是显示页面本身

请帮我解释一下,以及如何解决这个问题

对于任何语法错误和理解上的困难,我深表歉意:)

如上所述,如果您以前打印过一些html,则不能使用
标题。
(你甚至不能在之前留下空白)


只需删除
echo
,就可以了。

一旦
echo
任何内容或发送任何输出,您的头就会被发送。因此,在执行此操作后,您无法操纵标题。通过简单地搜索你的错误消息,你会发现很多关于这个问题的帖子

当你在下一行重定向它们时,回显它们有什么意义p


编辑:此语句中的美元符号有什么原因:
标题(“位置:$http://localhost/.../contacts.html");
$http
是一个变量吗?也许可以尝试删除美元符号。

在http之前删除
$
符号,这样就完成了…

虽然我们非常确定您会遇到什么错误,但请始终让我们知道实际的错误消息。谢谢,没有理由。我发得有点快,无法撤消。或者我可以?编辑:我不能。你可以试着标记你自己的答案,然后让mod撤销它。不知道那会有多道德。当然不道德,也不可能。我只是移动了“echo”。据我所知,头函数不能与echo一起使用对吗?呵呵..但我仍然无法直接转到contacts.html页面…当我签入firebug时,它只在响应部分显示contacts.html的html代码..为什么在firebug中的代码旁边不显示contacts.html页面?:p@muxisar版主可以撤销comm wiki。$符号不是一个变量。.我只是尝试使用从其他网站获得的建议代码。.但运气不好:p