###前提・実現したいこと
PHPでログインフォームを作っています。
http://stackoverflow.com/questions/26592629/using-pdo-and-sessions-to-create-a-login-form?answertab=votes#tab-top
上記のサイトを参考に作ってみました。
###発生している問題・エラーメッセージ
Notice: Undefined index: name in******/session.php on line 10 Warning: Cannot modify header information - headers already sent by (output started at ******/session.php:10) in *******/session.php on line 24
###該当のソースコード
【loginform.html】 <!doctype html> <html lang="ja"> <head> <meta charset="UTF-8"> <title>Loginform</title> </head> <body> <form role="form" class="omb_loginForm" action="login.php" autocomplete="off" method="POST"> <div class="input-group"> <span class="input-group-addon"><i class="fa fa-user"></i></span> <input type="email" class="form-control" name="email" placeholder="Email"> </div> <span class="help-block"></span> <div class="input-group"> <span class="input-group-addon"><i class="fa fa-lock"></i></span> <input type="password" class="form-control" name="password" placeholder="Password"> </div> <span class="help-block"></span> <button class="btn btn-lg btn-primary btn-block" name="submit" type="submit">Login</button> </form> </body> </html> 【dashboard.php】 <?php include('session.php'); ?> <!DOCTYPE html> <html> <head> <title>Your Home Page</title> <link href="style.css" rel="stylesheet" type="text/css"> </head> <body> <div id="profile"> <b id="welcome">Welcome : <i><?php echo $login_session; ?></i></b> <b id="logout"><a href="logout.php">Log Out</a></b> </div> </body> </html> 【session.php】 <?php $dbhost = "localhost"; $dbname = "abc"; //(←仮です) $dbuser = "root"; $dbpass = "wood"; //(←仮です) $conn = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass); session_start(); $user_check=$_SESSION['login_user']; $result = $conn->prepare("SELECT * FROM abc WHERE email= :usercheck"); $result->execute(array(":usercheck"=>$user_check)); $row = $result->fetch(PDO::FETCH_ASSOC); $login_session =$row['email']; $user_id =$row['id']; $user_passwords = $row['password']; if(!isset($login_session)) { $conn = null; header('Location: loginform.html'); } ?>
###疑問
session.phpの
$user_check=$_SESSION['login_user'];
の”login_user”がどこからきているのかがわかりません。
###補足情報(言語/FW/ツール等のバージョンなど)
言語 php : 5.6.10
エディタ phpstorm : 10.0.3
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/05/10 16:59
2016/05/10 17:17 編集
2016/05/11 12:52
2016/05/11 13:21 編集
2016/05/12 17:39