php标题在xampp上本地工作,但不在godaddy服务器上

时间:2014-02-05 15:53:57

标签: php header

我想重定向到adm/index.php文件if($count==1),但该页面只是刷新并停留在同一页面上。

我尝试了几种解决方案无济于事:

  1. 在开始<?php>
  2. 之前检查了空格
  3. 在开始<?php>
  4. 之前删除了所有html链接

    一切都在xxamp本地运行良好,但问题是在上传后,没有错误信息;只是同一页刷新,它是空白的。

    在主程序中调用两个函数;主程序还包含一些回声。是否可以使标题有效?

    $myusername = mysql_real_escape_string($myusername);
    $mypassword = mysql_real_escape_string($mypassword);
    $sql="SELECT * FROM adminlogin WHERE username = '$myusername' and password ='$mypassword'";
    $result=mysql_query($sql); // from adminlogin table, ngetasacco
    $sql2="SELECT * FROM memberslogin WHERE username = '$myusername' and password ='$mypassword'";
    $result2=mysql_query($sql2); // from the memberslogin table, ngetasacco
    
    // Mysql_num_row is counting table row
    $count = mysql_num_rows($result);
    $count2 = mysql_num_rows($result2);
    
    // If result matched $myusername and $mypassword, table row must be 1 row
    if($count==1)// only the admin
    {
    $_SESSION['myusername'] = myusername;
    $_SESSION['mypassword'] = mypassword;
    header("location: adm/index.php");
    }
    elseif($count2==1)// any registered member with access
    {
    $_SESSION['myusername'] = myusername;
    $_SESSION['mypassword'] = mypassword;
    header("location: adm/member.php");
    }
    else {
    echo "<musuya>Wrong username or Password</musuya><br/><br/>";
    //echo md5($mypassword);
    //$m=md5($mypassword);
    usernamePass();
    }
    ob_end_flush();
    }// end of function auth()
    function usernamePass()
    {
    echo "<form method='post' action=" . $_SERVER['PHP_SELF'] . ">";
    echo " username <input type='text' name='username' /><br/><br/>";
    echo "password <input type='password' name='password' value=''/><br/>";
    echo "<input type='submit' value='Login' />";
    }// end of function usernamePass()
    //++++++++++++++++++++++++++main program
    +++++++++++++++++++++++++++++++++++
    if(empty($_POST["username"]) || empty($_POST["password"]))
    { 
    echo"username and pasword cannot be empty</br></br>";
    usernamePass();
    }
    if(!(empty($_POST["username"])) && !(empty($_POST["password"])))
    {
    auth();
    }
    if(!empty($_GET['status']))
    {
    echo '<div>You have been logged out!</div>';
    }      
    //++++++++++++++++++++++++ end of main program
    ++++++++++++++++++++++++++++++
    ?>
    

    连接/ db_connect.php

    <?php
    $host="";// Host name
    $username="";//Mysql username
    $password="";//Mysql password
    $db_name="";//Database name
    $tbl_name="";//Table name
    //Connect to server and select databse.
    mysql_connect("$host", "$username", "$password");//or die("cannot connect");
    mysql_select_db("$db_name");//or die("cannot select DB");
    //echo "connected to server and dbase";
    ?>
    

1 个答案:

答案 0 :(得分:0)

ob_end_flush();添加到文件底部并进行检查

<?php
function auth(){
ob_start();
include"connections/db_connect.php";
// Define $myusername and $mypassword
$myusername=md5($_POST['username']);
$mypassword=md5($_POST['password']);
// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM adminlogin WHERE username = '$myusername' and password     = '$mypassword'";
$result=mysql_query($sql); // from adminlogin table, ngetasacco
$sql2="SELECT * FROM memberslogin WHERE username = '$myusername' and     password = '$mypassword'";
$result2=mysql_query($sql2); // from the memberslogin table, ngetasacco
// Mysql_num_row is counting table row
$count = mysql_num_rows($result);
$count2 = mysql_num_rows($result2);
// If result matched $myusername and $mypassword, table row must be 1 row
//if($count==1){
if($count==1)// only the admin
{
    $_SESSION['myusername'] = myusername;
    $_SESSION['mypassword'] = mypassword;
    //header("location: login_success.php");
    header("location: adm/index.php");
}
ob_end_flush();
?>