本文介绍了替代“标题"的示例性实施例.用于PHP中的重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个项目上,需要在别人的Web服务器上运行我的程序.这是我遇到问题的非常简单的登录页面.如果我通过WAMP在本地主机上运行该程序,则该程序将正常运行.我遇到的问题是重定向部分无法正常工作,它验证了用户并启动了会话,但是当它进入重定向时,什么也没发生.

I am working on a project and I am required to run my program on someone else's webserver. It is a pretty simple login page that I am having the problem with. The program works correctly if I run it through my local host via WAMP. The problem I am having is that the re-direct portion is not working correctly it validates the user and starts a session but when it gets to the redirect nothing happens.

我的语法有问题,我认为这不太可能,因为它可以通过我的本地主机正常工作.或者,我认为服务器不具有该功能(尽管我确定它是可行的,但不确定是否可以选择服务器所支持的模块).

I am either doing something wrong with my syntax which I think is highly unlikely since it does work correctly through my local host. Or alternatively I'm thinking that the server does not have that function (not sure if its possible to pick and choose which modules your server supports although I'm sure it's feasible).

我不知道这是否重要,但是他们使用的是"cpanel",在这里我可以访问文件,并且所有文件都位于同一目录中,因此,如果有人可以告诉我我要去哪里,或者建议重定向的另一种方法通过标题",任何帮助将不胜感激.我环顾四周,但似乎标头"是标准的工作马.

I don't know if it matters but they are using "cpanel" which is where I can access the files and there all in the same directory so if someone could tell me where I am going wrong or suggest an alternative to redirecting via "header" any help would be greatly appreciated. I've looked around but it seems that "header" is the standard work horse.

这里有我的代码:

if( (!empty($_POST['username'])) && (!empty($_POST['password'])) )
{
// username and password sent from Form 
$myusername = $_POST['username']; 
$mypassword = $_POST['password']; 


$sql="SELECT UserName FROM User WHERE UserName='$myusername' and        Password='$mypassword'";

$result=mysql_query($sql);

$row=mysql_fetch_array($result);
//$active=$row['active'];
$count=mysql_num_rows($result);

// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1)
{
    echo "we made if to the if";
    session_start();
    session_register("myusername");
    $_SESSION['login_user']=$myusername;
    echo "right b4 the re-direct";
    header("location: UI.php"); 
            exit;
}
else
    echo "Your user name/password was not correct pleast TRY AGAIN!!!";

} 

更新:响应有关回声的陈述,可能会出现以下问题:我正在同一文件中处理表单并使用回声$ _SERVER ['PHP_SELF']

Update: In response to the statements about the echos would the problem possible by that I am processing my form in the same file and using echo $_SERVER['PHP_SELF']

推荐答案

来自文档:

您的echo导致重定向失败,在标头之前发送的任何其他输出也是如此.

Your echo is causing the redirect to fail, as is any other output sent before the header.

这篇关于替代“标题"的示例性实施例.用于PHP中的重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 18:29