![](/img/trans.png)
[英]I have a problem oh login in php. When I test it in localhost, login page it worked. But when I upload it on server and test, it did not worked
[英]php login page worked in localhost but not in live server
我已經厭倦了找出為什么這個login.php可以在localhost環境中正常運行但不能在實時服務器中正常運行的麻煩。 登錄時,輸入錯誤的用戶名和密碼出錯,但在本地主機上則成功。 與db的連接正確。
任何人都可以幫助我檢查我的編碼。
下面是我的代碼
<?php require_once('Connections/conn.php'); ?>
<?php
session_start();
if(isset($_POST["s_username"]) && isset($_POST["s_password"])){
$s_username = $_POST["s_username"];
$s_password = $_POST["s_password"];
echo "<script>window.alert('$s_username - $s_password');</script>";
$sql= mysql_query("SELECT * FROM student WHERE studentNo = $s_username AND studentPswd = $s_password LIMIT 1");
$sql2= mysql_query("SELECT * FROM clockin WHERE studentNo = '$s_username' AND status=0 LIMIT 1");
$existCount = mysql_num_rows($sql);
$s_status = "1";
if($existCount==1){
while($row = mysql_fetch_array($sql)){
$s_no=$row['studentNo'];
$s_name=$row['studentName'];
}
if($existCount2==1){
while($row2 = mysql_fetch_array($sql2)){
$s_status=$row2['status'];
$s_clockid=$row2['clockID'];
}}
$_SESSION["s_no"]=$s_no;
$_SESSION["MM_Username"]=$s_username;
if($sql==true){
echo "<script>window.alert('Login Success');</script>";
</script>";
if($s_status==1){
header("refresh:1 ,url=beginSession.php ");
exit();
}
else {
echo "<script>window.alert('Sesi Lepas Belum Ditamatkan.');</script>";
header("refresh:1 ,url=startedSession2.php?clockid=$s_clockid");
exit();
}
}
}
else{
echo "<script>window.alert('Login Failed.');</script>";
header("refresh:1 ,url=login.php");
exit();
}
}
?>
<body>
<div class="wrapper-page">
<div class="panel panel-color panel-primary panel-pages">
<div class="panel-heading bg-img">
<div class="bg-overlay"></div>
<h3 class="text-center m-t-10 text-white"><strong>Masuk ke</strong>
<p><a href="#"><img src="img/logo2.png" alt="" title=""></a></p></h3>
</div>
<div class="panel-body">
<form class="form-horizontal m-t-20" id="form1" method="post" action="login.php">
<div class="form-group">
<div class="col-xs-12">
<input name="s_username" class="form-control input-lg" type="text" required="" placeholder="Username">
</div>
</div>
<div class="form-group">
<div class="col-xs-12">
<input name="s_password" class="form-control input-lg" type="password" required="" placeholder="Password">
</div>
</div>
<div class="form-group text-center m-t-40">
<div class="col-xs-12"><label>
<button class="btn btn-primary btn-lg w-lg waves-effect waves-light" type="submit" value="Log in">Log In</button></label>
<label><a href="reg2.php" class="btn btn-primary btn-lg w-lg waves-effect waves-light">Daftar Baru</a></label>
</div>
</div>
</form>
</div>
</div>
</div>
</body>
我希望有人能幫助我。
謝謝
嘗試這個
session_start();
require_once('Connections/conn.php');
session_start();
始終位於頁面頂部。
還刪除其他關閉:
echo "<script>window.alert('Login Success');</script>";
此代碼導致語法錯誤:
echo "<script>window.alert('Login Success');</script>";
</script>";
刪除其他</script>"
:
echo "<script>window.alert('Login Success');</script>";
https://www.tinywebhut.com/errors-and-custom-error-handling-in-php-56
小心
您正在使用已棄用的mysql
,而改用mysqli
擴展名。 我想您知道SQL注入。 始終使用准備好的語句。
准備好的語句已經有助於消除大量問題,以使查詢正常運行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.