關於課程
<form action=”loginoutput.php” method=”post”>
登入ID<input type=”text” name=”login”><br>
密碼<input type=”password” name=”password”><br>
<input type=”submit” value=”登入”>
</form>
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
<?php
session_start();
unset($_SESSION[‘customer’]);
$pdo=new PDO(‘mysql:host=localhost;dbname=shop;charset=utf8′,’root’, ‘12345678’);
$sql=$pdo->prepare(‘select * from customer where login=? and password=?’);
$sql->execute([$_REQUEST[‘login’], $_REQUEST[‘password’]]);
foreach ($sql->fetchAll() as $row) {
$_SESSION[‘customer’]=[
‘id’=>$row[‘id’], ‘name’=>$row[‘name’],
‘address’=>$row[‘address’], ‘login’=>$row[‘login’],
‘password’=>$row[‘password’]];
}
if (isset($_SESSION[‘customer’])) {
echo ‘親愛的’, $_SESSION[‘customer’][‘name’], ‘、歡迎光臨。’;
} else {
echo ‘登入ID或密碼有誤。’;
}
?>