下面是 index.html,它向用户显示密码和电子邮件输入表单
<!DOCTYPE html>
<html lang="en">
<head>
<title>Ryan Kelly</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="main.css" rel="stylesheet">
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="js/bootstrap.min.js"></script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-35774778-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body>
<?php include 'comments.php'; ?>
<div class="container">
<div class="centre">
<div class="well">
<h1 class="titlecomment">Comment System</h1>
<h4 class="instructions">Please login below with your username and password</h4>
<form class="form-horizontal">
<div class="control-group">
<label class="control-label" for="inputEmail">Email</label>
<div class="controls">
<input type="text" id="inputEmail" placeholder="Username" method="post">
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputPassword" >Password</label>
<div class="controls">
<input type="password" id="inputPassword" placeholder="Password" method="post">
</div>
</div>
<div class="control-group">
<div class="controls">
</div>
</div>
</form>
<div class="greenbutton">
<button type="submit" class="btn btn-success" method="login()">Login</button>
</div>
</div>
<div class="footer">Created by Ryan Kelly</div>
</div>
</div>
下面是检查电子邮件和密码然后将用户重定向到谷歌的 PHP 脚本,我只是重定向,因为我想看看它是否成功登录
<?php
function login() {
$connection = mysql_connect($host, $databaseUsername, $databasePassword);
$username = $_POST['inputEmail'];
$password = $_POST['inputPassword'];
mysql_select_db($connection);
$queryUsername = "SELECT * FROM login WHERE Username='$username'";
$queryPassword = "SELECT * FROM login WHERE Password='$password'";
$searchQuery = mysql_query($queryUsername);
$searchQueryDatabase = mysql_query($queryPassword);
if($searchQuery && $searchQueryDatabase = $username && $password) {
header('Location: http://www.google.co.uk');
}
}
?>