那你好!我根本无法理解为什么这个登录页面不起作用。我之前在php 5.4的共享服务器上运行它。我将网站移动到我自己的服务器上,运行Ubuntu 12.04,apache 2.4.6,php 5.5。
我只是在下面显示整个登录文件,globals.php包含mysql连接,它有效。
如果我遗漏了任何信息,请告诉我。
只需在if语句中测试print语句,我认为在if(prepare)之后失败了。
问题是,在您尝试登录后,它会在该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>
答案 0 :(得分:0)
尝试更改此
$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>";
}
到
$stmt->bind_param('ss', $user, $pass);
$stmt->store_result();
$stmt->execute();
if ($stmt->num_rows==1)
{
$stmt->bind_result($id, $username, $password);
$stmt->fetch();
print "<script>alert('You are logged in! Check the menu \"Admin\" section for more information!');</script>";
}