**//code for Login.php:**
<?php
session_start();
require 'vendor/autoload.php';
$client = new Aws\Rds\RdsClient([
'region' => 'us-west-2',
'version' => 'latest'
]);
$result = $client->describeDBInstances([
'DBInstanceIdentifier' => 'itmo-chandu'
]);
$endpoint = $result['DBInstances'][0]['Endpoint']['Address'];
print_r($endpoint);
**// Create connection**
$db = mysqli_connect($endpoint,"controller","iloveuchandu","login") or die("Error " . mysqli_error($db));
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
if (isset($_POST["username"]) && isset($_POST["password"])) {
**// username and password sent from form**
$myusername = mysqli_real_escape_string($db,$_POST['username']);
$mypassword = mysqli_real_escape_string($db,$_POST['password']);
$sql = "SELECT id FROM admin WHERE username = '$myusername' and password = '$mypassword'";
$result = mysqli_query($db,$sql);
$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
$active = $row['active'];
$count = mysqli_num_rows($result);
**// If result matched $myusername and $mypassword, table row must be 1 row**
if($count > 0) {
$_SESSION['login_user'] = $myusername;
header("location: welcome.php");
}else {
$error = "Your Login Name or Password is invalid";
}
}
?>
<html>
<head>
<title>Login Page</title>
<style type = "text/css">
body {
font-family:Arial, Helvetica, sans-serif;
font-size:14px;
}
label {
font-weight:bold;
width:100px;
font-size:14px;
}
.box {
border:#666666 solid 1px;
}
</style>
</head>
<body bgcolor = "#FFFFFF">
<div align = "center">
<div style = "width:300px; border: solid 1px #333333; " align = "left">
<div style = "background-color:#333333; color:#FFFFFF; padding:3px;"><b>Login</b></div>
<div style = "margin:30px">
<form action = "" method = "post">
<label>UserName :</label><input type = "text" name = "username" class = "box"/><br /><br />
<label>Password :</label><input type = "password" name = "password" class = "box" /><br/><br />
<input type = "submit" value = " Submit "/><br />
</form>
</div>
</div>
</div>
</body>
</html>
**//code for Welcome.php**
<?php
session_start();
$user_check = $_SESSION['login_user'];
require 'vendor/autoload.php';
$client = new Aws\Rds\RdsClient([
'region' => 'us-west-2',
'version' => 'latest'
]);
$result = $client->describeDBInstances([
'DBInstanceIdentifier' => 'itmo-chandu'
]);
$endpoint = $result['DBInstances'][0]['Endpoint']['Address'];
print_r($endpoint);
**// Create connection**
$db = mysqli_connect($endpoint,"controller","iloveuchandu","login")or die("Error " . mysqli_error($db));
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$sesss="SELECT username from admin where username = '$user_check' ";
$ses_sql=mysqli_query($db,$sesss);
$row = mysqli_fetch_array($ses_sql,MYSQLI_ASSOC);
$login_session = $row['username'];
if(!isset($_SESSION['login_user'])){
header("location:login.php");
}
?>
<html>
<head>
<title>Welcome </title>
</head>
<body>
<h1>Welcome <?php echo $login_session; ?></h1>
</body>
</html>
を使用してPHPのログインページを作成します。Imは私がwelcome.phpについては、以下のエラーが取得していアマゾンRDSサーバーに
PHPのお知らせ:未定義のインデックス:/var/www/html/welcome.phpでLOGIN_USERをオンライン5 **。
どこが間違っているのか分かりませんのでお手伝いください。 $_SESSION
にはユーザー名を持つものがありますか?**
**パスワードをプレーンテキストとして保存しない**攻撃者(または悪意のある管理者)があなたのデータベースを保持する瞬間、*あなたのすべてのユーザーの資格情報が侵害されます。安全なハッシュを作成するには 'password_hash()'を、それを検証するには 'password_verify()'を使います。 –
セッションが存在するかどうかを確認する必要があります。セッションが空であるように見えます –
これは、MySQL、AWS、またはRDSとは関係ありません。 – ceejayoz