JQuery无法在顶部使用PHP
JQuery not working on PHP on top
我试着在我的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变量的形式传递密码,也就是在查询字符串中,供所有人查看
- 您正在将未初始化的用户数据与数据库查询一起传入
- 你没有以任何方式散列密码
- 等等
相关文章:
- 使用php或javascript从facebook相册URL中删除多余的部分
- 将PHP变量传递给jQuery时遇到问题
- 通过javascript重定向html传递php变量
- 将数组从PHP传递到Javascript
- 如何在php文件中获取$.post-ajax传递的值
- Javascript运行php文件,然后下载文件
- PHP中的setcookie仅适用于localhost
- 如何使用jquery处理php循环通过元素
- 通过Ajax将JavaScript函数传递给PHP文件
- 而循环只设置php中输入字段中的第一个值
- 我需要从php调用javascript或jquery
- 使用 Jquery 删除页面顶部的 PHP 错误消息
- 在 PHP 中获取顶部框架(浏览器中的地址栏)URL
- responseText正在返回我的php文件的顶部
- PHP/JavaScript发布到顶部
- JQuery无法在顶部使用PHP
- JavaScript在PHP页面的顶部不工作
- 改变总是在顶部的菜单与褪色的php/js
- 我如何阻止一个页面从滚动到顶部时,在php单击按钮
- PHP/CSS中的一个特殊函数,其中一个页面位于另一个页面的顶部