だから私は自分のウェブサイトの PHP/SQL ログイン スクリプトに取り組んでいます。サーバーは Apache を実行する UNIX システムであり、PHP がインストールされていることは確かです。SQL データベースをセットアップし、PHP コードをセクションに分割しました。
http://www.woodlandastronomy.org/login.php :
<?php
session_start();
require_once 'http://www.woodlandastronomy.org/cgi-bin/classes/membership.php';
$membership = new Membership()
if($_POST && !empty($_POST['username']) && !empty($_POST['pwd'])) {
$response = $membership->validate_User($_POST['username'], $_POST['pwd']);
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="description" content="Woodland Astronomy Club Website">
<meta name="keywords" content="Woodland, Astronomy, Club, Website, Moss, Lake, Neighborhood, Astronomical, Association">
<link rel="stylesheet" href="wasmain.css">
<link rel="icon" href="http://www.woodlandastronomy.org/favicon.ico" type="image/x-icon">
<script type="text/javascript" src="script1.js"></script>
<title>Woodland Astronomy Club - Home</title>
</head>
<body>
<div id="container">
<div id="header">
<img src="IMG_9897 2 (3) copy.jpg" alt="we has a issue, sorrys!1!!!" width="100%" height="200px">
<div id="linkbar">
<p class="linkbarbutton">
<b><a class="linkbarlink" href="http://www.woodlandastronomy.org/index.html">Home</a></b>
</p>
<p class="linkbarbutton"><b><a class="linkbarlink" href="http://www.woodlandastronomy.org/aboutus.html">About Us</a></b></p>
<p class="linkbarbutton"><b><a class="linkbarlink" href="http://www.woodlandastronomy.org/events.html">Club Events</a></b></p>
<p class="linkbarbutton"><b><a class="linkbarlink" href="http://www.woodlandastronomy.org/eventpix.html">Club Photos</a></b></p>
<p class="linkbarbutton"><b><a class="linkbarlink" href="http://www.woodlandastronomy.org/astropix.html">Astrophotography</a></b></p>
<p class="linkbarbutton"><b><a class="linkbarlink" href="http://www.weatherlink.com/user/theweathercat/" target="_blank">Weather Station</a></b></p>
<p class="linkbarbutton"><b><a class="linkbarlink" href="http://www.woodlandastronomy.org/contact.html">Contact Us</a></b></p>
<p class="linkbarbutton"><b><a class="linkbarlink" href="http://www.woodlandastronomy.org/links.html">External Links</a></b></p>
<p class="linkbarbutton"><b><a class="linkbarlink" href="http://www.woodlandastronomy.org/members.html">Members</a></b></p>
</div>
</div>
<div id="content">
<div id="fluffy"></div>
<div id="login">
<form method="post" action="">
<h2 class="yellowlabel">Login <small>Enter Your Credentials</small></h2>
<p class="yellowlabel">
<label for="username" >Username: </label>
<input type="text" name="username">
</p>
<p class="yellowlabel">
<label for="password">Password: </label>
<input type="password" name="pwd">
</p>
<p>
<input type="submit" id="submit" value="Login" name="submit">
</p>
</form>
<?php
if(isset($response)) echo "<h4 class='alert'>" . $response . "</h4>";
?>
</div>
</div>
</div>
</body>
</html>
それから、
http://www.woodlandastronomy.org/cgi-bin/classes/membership.php :
<?php
require 'http://www.woodlandastronomy.org/cgi-bin/classes/Mysql.php';
class Membership {
function validate_user($un, $pwd) {
$mysql = New Mysql();
$ensure_credentials = $mysql->verify_Username_and_Pass($un, $pwd);
if($ensure_credentials) {
$_SESSION['status'] = 'authorized';
header("location: http://www.woodlandastronomy.org/members.html");
} else return "Please enter a correct username and password";
}
}
?>
それから、
http://www.woodlandastronomy.org/cgi-bin/classes/mysql.php :
<?php
require_once 'http://www.woodlandastronomy.org/cgi-bin/classes/constants.php';
class Mysql {
private $conn;
function __construct() {
$this->conn = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME) or
die('There was a problem connecting to the database.');
}
function verify_Username_and_Pass($un, $pwd) {
$query = "SELECT *
FROM Membership
WHERE username = ? AND password = ?
LIMIT 1";
if($stmt = this->conn->prepare($query)) {
$stmt->bind_param('ss', $un, $pwd);
$stmt->execute();
if($stmt->fetch()) {
$stmt->close();
return true;
}
}
}
}
?>
そして最後に、
http://www.woodlandastronomy.org/cgi-bin/classes/constants.php :
<?php
define('DB_SERVER', 'localhost');
define('DB_USER', '/*I didn't want to put my database credentials on the web, you understand...');
define('DB_PASSWORD', '');
define('DB_NAME', 'Member');
?>
そのため、以前はページが完全に空白でしたが、それはインクルード ファイルの構文エラーでした。これを見つけた後、PHP が MySQL データベースに接続できないというエラー メッセージが表示されるようになりました。さらに作業を行った後、エラー メッセージを完全に取り除くことができましたが、[ログイン] をクリックすると、ブラウザが最終的に「サーバーへの接続がリセットされました」というメッセージを表示するまでロードを試行するだけです。
道に迷いました。私の隣人は PHP に長けていますが、彼は今日の午後から町を離れており、自分でこれを理解することはできないようです。
誰かが私が間違っていることを教えてくれたら、それは素晴らしいことです。
非常に長い質問で申し訳ありません。
ありがとう、ハロルド