首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >PHP MySQL登录可在本地服务器上运行,但不能在公共服务器上运行

PHP MySQL登录可在本地服务器上运行,但不能在公共服务器上运行
EN

Stack Overflow用户
提问于 2018-06-17 20:03:50
回答 1查看 67关注 0票数 0

我尝试了一下PHP和sql,发现它很容易注入MySQL。所以我更改了一些东西,所以我使用了$smtp,而不是$query等等。

页面在我的本地服务器(xammp)上加载并工作,但是当我将它上传到公共服务器时,我得到一个500内部服务器错误(页面在更改之前工作)

我没有对HTML做任何修改,只有PHP部分出了问题。

这是我的代码,它在本地服务器上运行,但在公共服务器上运行的是,而不是

代码语言:javascript
复制
<?php
session_start();
 require('../db/DBconnect.php');
 $select_db = mysqli_select_db($connection, 'website');
if (!$select_db){
    die("Database Selection Failed" . mysqli_error($connection));
}

if (isset($_POST['username']) and isset($_POST['password'])){

$username = $_POST['username'];
$password = $_POST['password'];
//$query = "SELECT * FROM `users` WHERE userName='$username' and userPass='$password'"; OLD LOGIN
$stmt = $connection->prepare('SELECT * FROM users WHERE userName= ? and userPass= ?');
$stmt->bind_param('is', $username, $password);

$stmt->execute();

//$result = $stmt->get_result(); OLD LOGIN
//while ($row = $result->fetch_assoc()) { OLD LOGIN
    // do something with $row OLD LOGIN
//} OLD LOGIN
$result = $stmt->get_result();
//$result = mysqli_query($connection, $stmt) or die(mysqli_error($connection)); OLD LOGIN
$count = mysqli_num_rows($result);
if ($count == 1){
$_SESSION['username'] = $username;
}else{
$fmsg = "Invalid Login Credentials.";
}
}
if (isset($_SESSION['username'])){
$username = $_SESSION['username'];
header('Location: /beta/adminpanel.php');
}else{
?>
<!DOCTYPE html>
<base href="/">
  <html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Admin - Freunde Gamen &hearts;</title>
    <link href="../host-files/bootstrap.css" rel="stylesheet">
    <link href="../host-files/admin.css" rel="stylesheet">
<html>
<head>
  <base href="/">
    <link rel="icon" href="../favicon.ico" type="image/x-icon"/>
</head>
  <body>
<div class="container">
    <div class="login">

      <form class="form-signin" method="POST">
      <?php if(isset($fmsg)){ ?><div class="alert alert-danger" role="alert"> <?php echo $fmsg; ?> </div><?php } ?>
        <h2 class="form-signin-heading">FG - Admin Login</h2>
        <div class="input-group">
    <span class="input-group-addon" id="basic-addon1">@</span>
    <input type="text" name="username" class="form-control" placeholder="Username" required>
  </div>
        <label for="inputPassword" class="sr-only">Password</label>
        <input type="password" name="password" id="inputPassword" class="form-control" placeholder="Password" required>
        <button class="btn btn-lg btn-primary btn-block" type="submit">Login</button>
      </form>
</div>
    </div>
    <script src="../host-files/js/bootstrap.js"></script>
    <script src="../host-files/js/jquery.min.js"></script>


</body></html>
<?php } ?>

本地和公共服务器使用:

Apache/2.4.10

PHP版本5.6.33-0+deb8u1 (我知道我应该更新到PHP 7)

共享相同的MySQL数据库和服务器

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-18 00:54:20

因此,在将此代码添加到admin.php之后:

// DEBUGGING error_reporting(E_ALL); ini_set('display_errors', true);

我意识到我的公共服务器上缺少mysqli_mysqlnd.dll软件包,所以我安装了它。

sudo apt-get install php5-mysqlnd

,它成功了!谢谢大家!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50896444

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档