2017-01-25 7 views
0

ユーザーがフォームを送信すると、フォーム検証メッセージ(php経由)がヘッダーに表示されます。ヘッダにPHP検証メッセージが表示される

メッセージを本文(フォームの下)に表示する方法を教えてください。以下のコード。 Screen shot attached for clarification

<? 
/* Check User Script */ 
session_start(); // Start Session 

include 'db.php'; 
// Conver to simple variables 
$username = $_POST['username']; 
$password = $_POST['password']; 

if((!$username) || (!$password)){ 
echo "Please enter ALL of the information! <br />"; 
include 'login_form.html'; 
exit(); 
} 

// Convert password to md5 hash 
$password = md5($password); 

// check if the user info validates the db 
$sql = mysql_query("SELECT 
* 
FROM users u 
WHERE 
username='$username' 
AND password='$password' 
AND activated='1' 
AND u.email_address IN (SELECT email from authorized_doctors) 
    "); 
$login_check = mysql_num_rows($sql); 

if($login_check > 0){ 
while($row = mysql_fetch_array($sql)){ 
foreach($row AS $key => $val){ 
    $$key = stripslashes($val); 
} 
    // Register some session variables! 
    session_start('first_name'); 
    $_SESSION['first_name'] = $first_name; 
    session_start('last_name'); 
    $_SESSION['last_name'] = $last_name; 
    session_start('email_address'); 
    $_SESSION['email_address'] = $email_address; 
    session_start('special_user'); 
    $_SESSION['user_level'] = $user_level; 

    mysql_query("UPDATE users SET last_login=now() WHERE 
    userid='$userid'"); 

    header("Location: login_success.php"); 
    } 
    } else { 
echo "<br>You could not be logged in! Either the username and 
password do not match or you have not validated your membership! 
Please try again!<br />"; 
include 'login_form.html'; 
} 
?> 
+1

***してください[ 'mysql_ *'関数を使用して停止](http://stackoverflow.com/questions/12859942 /why-shouldnt-i-use-mysql-functions-in-php).*** [これらの拡張機能](http://php.net/manual/en/migration70.removed-exts-sapis.php)はPHP 7で削除されました。[PDO](http://php.net/manual/en/pdo.prepared-statements.php)の[prepared](http://en.wikipedia.org/wiki/Prepared_statement) )と[MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php)を使って、PDOの使用を検討してください。[これは本当に簡単です](http://jayblanchard.net/de mystifying_php_pdo.html)。 –

+0

[Little Bobby](http://bobby-tables.com/)によると*** [あなたのスクリプトはSQLインジェクション攻撃の危険にさらされています。](http://stackoverflow.com/questions/60174/how-can- i-prevent-sql-in-php)***。 [文字列をエスケープする](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string)でも安全ではありません! –

+0

***あなたは本当に[MD5パスワードハッシュ](http://security.stackexchange.com/questions/19906/is-md5-considered-insecure)***を使用すべきではありません。本当にPHPの[ in functions](http://jayblanchard.net/proper_password_hashing_with_PHP.html)を参照してください。ハッシュする前に[パスワードを逃さないでください](http://stackoverflow.com/q/36628418/1011527)を確認するか、他のクレンジングメカニズムを使用してください。パスワードを変更すると、パスワードが変更され、不要な追加のコーディングが発生します。 –

答えて

1

だけ出力あなたのinclude AFTERしたいデータ:

... 
} else { 
    include 'login_form.html'; 
    echo "<br>You could not be logged in! Either the 
       username and password do not match or you have not validated your membership! 
      Please try again!<br />"; 
} 
?> 
1

あなたは、変数と出力にしたい位置で、この変数をメッセージに割り当てることができます。たとえば、次のように

$message = '<br>You could not be logged in! Either the username and 
password do not match or you have not validated your membership! 
Please try again!<br />'; 

include 'login_form.php'; 

そしてlogin_form.phpのようなもの:

... 
<a href="">Forgot password?</a> 
<?php echo $message; ?> 
... 
関連する問題