LoginSignup
0
0

More than 3 years have passed since last update.

ログイン機能例

Posted at
<?php

try
{

$post=sanitize($_POST);
$staff_code=$post['code'];
$staff_pass=$post['pass'];

$staff_pass= md5($staff_pass);

$dsn = 'mysql:dbname=hoge;host=localhost;charset=utf8';
$user='root';
$password='';
$dbh = new PDO($dsn, $user, $password);
$dbh->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);

$sql = 'SELECT name FROM mst_staff WHERE code=? AND password=?';
$stmt = $dbh->prepare($sql);
$data[]=$staff_code;
$data[]=$staff_pass;
$stmt->execute($data);

$dbh =null;

$rec = $stmt->fetch(PDO::FETCH_ASSOC);

if($rec==false)
{
  print 'スタッフコードかパスワードが間違っています。<br/>';
  print '<a href="staff_login.html">戻る</a>';
}
else
{
  // $recがtrueであればログイン成功です
  session_start();
  $_SESSION['login']=1;
  $_SESSION['staff_code']=$staff_code;
  $_SESSION['staff_name']=$rec['name'];
  header('Location: staff_top.php');
  exit();
}
}
catch(Exception $e)
{
  print 'ただいま障害により大変ご迷惑をお掛けしております。';
  exit();
}

?>
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0