你好!我简直无法理解为什么这个登录页面不起作用。我之前使用 php 5.4 在共享服务器上运行过它。我将站点转移到我自己的服务器上,运行 Ubuntu 12.04、apache 2.4.6、php 5.5。
我只是在下面显示整个登录文件,globals.php 包含 mysql 连接,它可以工作。
如果我遗漏了任何信息,请告诉我。
只需通过在 if 语句中测试 print 语句,我认为它在 if (准备)之后失败了。
问题是,在您尝试登录后,它会在 if 语句之后显示一个空白页面。
再次感谢您提前提供的所有帮助,如果我没有提供足够的信息,请告诉我。
我不知何故有一种感觉,它与 mysqli 连接 vs mysql vs PDO 有关?
<?php
include( "globals.php" );
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<?php
newHead("GWHS Login", "/css/style.css"); //@param: title of site, link to css (default: http://gwhs.kana.k12.wv.us/css/style.css
?>
<body>
<?php
newBorder(); //create page border @param: width of border in px (default: 5px)
newLogo();
if (($_POST['username']) && ($_POST['password']))
{
$user = $_POST['username'];
$pass = md5($_POST['password']);
$stmt = $db->stmt_init();
if ($stmt->prepare("SELECT id, username, password FROM updateusers WHERE username = ? and password = ? LIMIT 1"))
{
$stmt->bind_param('ss', $user, $pass);
$stmt->execute();
$res = $stmt->get_result();
$row = $res->fetch_assoc();
if ($res->num_rows==1)
{
$_SESSION['username'] = $user;
$_SESSION['userid'] = $row['id'];
$_SESSION['type'] = 1;
$_SESSION['LAST_ACTIVITY'] = time();
print "<script>alert('You are logged in! Check the menu \"Admin\" section for more information!');</script>";
}
else {
echo "<script>alert('Wrong user / pass');</script>";
}
$stmt->close();
}
}
?>
<div id = "wrap"> <!-- Used to constrain the page width to 70% and center the page. -->
<?php
$links = array( array("Link to page", "Title of page"), //LEAVE BLANK IF USING MAIN MENU
array("Link to page 2", "Title of page 2"),
array("Link to page 3", "Title of page 3")
);
newNavigation (); //create menu @param: $use boolean, use the main? and $links = if not using main, what are your links NO DROPDOWN SUPPORT.
?>
<div id ='main'> <!-- This is the left block of the main content -->
<h1>GWHS Editor Login</h1>
<form method = "POST" action = "login.php">
Username: <input type="text" name="username"><br>
Password: <input type="password" name="password"><br>
<input type="submit" value="Login">
</form>
</div>
<?php newSidebar(); //creates new sidebar?>
<?php
newFooter(); //displays footer @param: $content (default: 'Copyright (c) 2012 - 2013, Design : <a href = "http://ankurk.com">AK</a>')
?>
</div>
</body>
</html>