JQuery无法在顶部使用PHP

JQuery not working on PHP on top

本文关键字:PHP 顶部 JQuery      更新时间:2023-09-26

我试着在我的cpanel主机上运行这个,但没有结果。当我在电脑上尝试使用localhost时,页面会重新加载。

假设该页面在使用登录系统时显示加载效果

这是我的代码

<?php 
require_once('Connection/connect.php'); 
$name = $_GET['username'];
$pwd = $_GET['password'];
?>
<?php
$linktemp="http://$_SERVER[HTTP_HOST]" . "/PointerSystem";
if( ($_GET['username']==NULL) || ($_GET['password']==NULL) )    {
header("Location:index.php?mode=empty");
        exit();
}   else
{
    mysql_select_db($database, $connect) or die(mysql_error());
    $query = "SELECT * FROM user WHERE matricID='$name' && password ='$pwd' LIMIT 1";
    $result = mysql_query($query);
    $count = mysql_num_rows($result);
    $row = mysql_fetch_assoc($result);
    if( $name=="" || $pwd=="" ) {
        header("Location:index.php?mode=empty");
        exit();
    }   elseif(($row['matricID']==$name) && ($row['password']==$pwd) )      {
        $p1 = $row['matricID'];
        $p2 = $row['password'];
         session_start();
        $_SESSION['name'] = $row['matricID'];
        ?>
            <script language="javascript" type="text/javascript" > window.setTimeout(function() { window.location = 'mainmenu.php'; }, 3000); </script>
            <?php
    }elseif (($row['matricID']!=$name) || ($row['password']!=$pwd) )/*|| ($row['level']!="admin")  || ($row['level']!="user")*/ {
            header("Location:index.php?mode=wrong");
            exit();
    }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Direct Login</title>
<link rel="stylesheet" type="text/css" href="css/loading.css" />
<link rel="stylesheet" type="text/css" href="css/loading2.css" />
<link rel="stylesheet" type="text/css" href="css/loading4.css" />
<link rel="stylesheet" type="text/css" href="css/loading5.css" />
<script src="js/loading.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>
<body style="background: #fff url('images/bg.jpg') repeat top left;">
<div id="loading2">
<p id="loading-font2">Redirect......</p>
  <img id="loading-image2" src="images/ajax-loader2.gif" />
</div>
<div id="loading">
<p id="loading-font">Please Wait, Validation In Progress......</p>
  <img id="loading-image" src="images/ajax-loader.gif" />
</div>
<script language="javascript" type="text/javascript">
$(window).load(function(){ $("#loading").hide().delay(700).show(0); $("#loading").fadeOut(5000);});
$(window).on("load",function() { $("#loading2").delay(600).fadeOut(2); $("#loading2").show(); });
</script>

</body>
</html>

问题已解决在@TUNAMAXX guid上,我已经更改了上面的代码,所以这里是更正代码。感谢@TUNAMAXX和@vlzvl。已经设法发布了数据。

<?php require_once('Connection/connect.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Direct Login</title>
<link rel="stylesheet" type="text/css" href="css/loading.css" />
<link rel="stylesheet" type="text/css" href="css/loading2.css" />
<link rel="stylesheet" type="text/css" href="css/loading4.css" />
<link rel="stylesheet" type="text/css" href="css/loading5.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>
<body style="background: #fff url(images/bg.jpg) repeat top left;">
<?php
$name = $_POST['username'];
$pwd = $_POST['password'];
/*$linktemp="http://$_SERVER[HTTP_HOST]" . "/PointerSystem";*/
if( ($_POST['username']==NULL) || ($_POST['password']==NULL) )  {
header("Location:index.php?mode=empty");
        exit();
}   else
{
    mysql_select_db($database, $connect) or die(mysql_error());
/* -------------------------------------------------------------------------------------------
* I still don't search about SQL Inject yet,Comic that you give me seem like troll Comic ^_^ 
* ---------------------------------------------------------------------------------------- */
    $query = "SELECT * FROM user WHERE matricID='$name' && password ='$pwd' LIMIT 1";
    $result = mysql_query($query);
    $count = mysql_num_rows($result);
    $row = mysql_fetch_assoc($result);
    if( $name=="" || $pwd=="" ) {
        header("Location:index.php?mode=empty");
        exit();
    }   elseif(($row['matricID']==$name) && ($row['password']==$pwd) )      {
/* -------------------------------------------------------------------------------------------
* I thought wanna use this as holder name or Welcome : USER . But not here 
* ---------------------------------------------------------------------------------------- */
        $p1 = $row['matricID'];
        $p2 = $row['password'];
         session_start();
        $_SESSION['name'] = $row['matricID'];

            echo"<script>
window.setTimeout(function() {
    window.location = 'mainmenu.php';
  }, 3000);
</script>";
    }elseif (($row['matricID']!=$name) || ($row['password']!=$pwd)) {
            header("Location:index.php?mode=wrong");
            exit();
    }
}
?>
<div id="loading2">
<p id="loading-font2">Redirect......</p>
  <img id="loading-image2" src="images/ajax-loader2.gif" />
</div>
<div id="loading">
<p id="loading-font">Please Wait, Validation In Progress......</p>
  <img id="loading-image" src="images/ajax-loader.gif" />
</div>
<script language="javascript" type="text/javascript">
$(window).load(function(){
      $("#loading").hide().delay(700).show(0);
     $('#loading').fadeOut(5000);
});
  $(window).on("load",function() {
   $("#loading2").delay(600).fadeOut(2);
$("#loading2").show();
  });
</script>

</body>
</html>

这段代码中有很多错误。第一种是在header()调用之前输出任何空白。例如,第5行和第7行上的打开和关闭PHP标记会在的第6行上生成一个换行符。这会破坏第一个header()重定向。

我将尽可能多地运行代码,并带回尽可能多的修复程序。

编辑:以下是一些经过清理/稍微修复的代码。这个代码目前可能"有效",但它很可怕。请勿在生产环境中使用

<?php 
    require_once('Connection/connect.php');
    /* --------------------------------------------------------------
     * Explicitly set variable values, even if you make them null
     * ------------------------------------------------------------ */
    $name = isset($_GET['username']) ? $_GET['username'] : null;
    $pwd  = isset($_GET['password']) ? $_GET['password'] : null;
    /* --------------------------------------------------------------
     * You assign this and then never use it?
     * ------------------------------------------------------------ */
    $linktemp = "http://$_SERVER[HTTP_HOST]" . "/PointerSystem";
    if (($name == NULL) || ($pwd == NULL))
    {
        header("Location:index.php?mode=empty");
        exit();
    }
    else
    {
        mysql_select_db($database, $connect) or die(mysql_error());
        /* --------------------------------------------------------------
         * You have opened yourself up for s SQL injection attack here.
         * Use the modern mysqli_* functions or PDO, and make sure you
         * ALWAYS SANITIZE YOUR INPUTS before sending it to the database
         * See: http://xkcd.com/327/
         * ------------------------------------------------------------ */
        $query  = "SELECT * FROM user WHERE matricID='$name' && password ='$pwd' LIMIT 1";
        $result = mysql_query($query);
        $count  = mysql_num_rows($result);
        $row    = mysql_fetch_assoc($result);
        /* --------------------------------------------------------------
         * Why do you have this test here? It is the same test as on
         * line 15. If we failed it then, we're certainly going to fail
         * it again now.
         * ------------------------------------------------------------ */
        if( $name == "" || $pwd == "" )
        {
            header("Location:index.php?mode=empty");
            exit();
        }
        elseif (($row['matricID'] == $name) && ($row['password'] == $pwd))
        {
            /* --------------------------------------------------------------
             * You assign these and then never use them?
             * ------------------------------------------------------------ */
            $p1 = $row['matricID'];
            $p2 = $row['password'];
            session_start();
            $_SESSION['name'] = $row['matricID'];
            /* --------------------------------------------------------------
             * You can get away with closing PHP here...
             * ------------------------------------------------------------ */
?>
            <script language="javascript" type="text/javascript" > window.setTimeout(function() { window.location = 'mainmenu.php'; }, 3000); </script>
<?php
            /* --------------------------------------------------------------
             * ...and then opening PHP here because in this part of the if()
             * statement, you are not doing a header() redirect. If you were,
             * would break right here because you output ** anything **
             * before a header() call and PHP will pitch a fit.
             * 
             * HOWEVER, avoid intermixing PHP and HTML like this. It will be
             * nightmare to troubleshoot in the future. Yes, PHP will let
             * you dothings like this, but it's rarely a good idea.
             * ------------------------------------------------------------ */
        }
        elseif (($row['matricID'] != $name) || ($row['password'] != $pwd))
        {
            header("Location:index.php?mode=wrong");
            exit();
        }
    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Direct Login</title>
        <link rel="stylesheet" type="text/css" href="css/loading.css" />
        <link rel="stylesheet" type="text/css" href="css/loading2.css" />
        <link rel="stylesheet" type="text/css" href="css/loading4.css" />
        <link rel="stylesheet" type="text/css" href="css/loading5.css" />
        <script src="js/loading.js" type="text/javascript"></script>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    </head>
    <body style="background: #fff url('images/bg.jpg') repeat top left;">
        <div id="loading2">
            <p id="loading-font2">Redirect......</p>
            <img id="loading-image2" src="images/ajax-loader2.gif" />
        </div>
        <div id="loading">
            <p id="loading-font">Please Wait, Validation In Progress......</p>
            <img id="loading-image" src="images/ajax-loader.gif" />
        </div>
        <script language="javascript" type="text/javascript">
            $(window).load(function(){ $("#loading").hide().delay(700).show(0); $("#loading").fadeOut(5000);});
            $(window).on("load",function() { $("#loading2").delay(600).fadeOut(2); $("#loading2").show(); });
        </script>
    </body>
</html>

我有一种感觉,这个代码会工作,但它有一些严重的问题:

  • 存在令人困惑的逻辑错误
  • 您正在以$_GET变量的形式传递密码,也就是在查询字符串中,供所有人查看
  • 您正在将未初始化的用户数据与数据库查询一起传入
  • 你没有以任何方式散列密码
  • 等等