2016-05-19 5 views
0

Windows @ 10でxampp Apacheサーバーをサーバー@ localhostで実行しています。 PHPコードがうまくいかず、問題があるようですか?PHPログインエラーの基本

PS私は任意のヘルプははるかに

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 

<html> 
<head> 
<TITLE>Welcome</TITLE> 
</head> 
<body> 
<form action="" method=POST> 
<div> 
<strong>Username:</strong><input type="text" name="username" value=""><br/> 
<strong>Password:</strong><input type="password" name="password" valuse=""><br/> 
<input type="submit" name="submit" value="Submit"><br/> 
</div> 
</forum> 
<?php 
    session_start(); 
    echo "Hello world!"; 
    include('sql_connect.db.php'); 
    if(isset($_POST[submit])){ 
    $uname=$_POST['username'] 
    $pass=$_POST['password'] 
    } 
    $result = mysql_query("SELECT * FROM users WHERE username=$uname") 
    $row=mysql_fetch_array($result); 
    $flag=0 
    if($row) 
    $usp=$row['password'] 
    if (pass==usp){ 
    $_SESSION['login_user'] = $uname; 
    header("location: success.php"); 
    }else { 
     $error = "Your Login Name or Password is invalid"; 
     } 
    ?> 
</body> 
</html> 
+1

を理解されるであろう、PHPを勉強しています** WARNING **:自分のアクセス制御層を書くことは容易ではない、それはひどく間違って取得するための多くの機会があります。 [Laravel](http://laravel.com/)のような最新の[開発フレームワーク](http://codegeekz.com/best-php-frameworks-for-developers/)がある場合は、独自の認証システムを作成しないでください。強力な[認証システム](https://laravel.com/docs/5.2/authentication)が組み込まれています。絶対に[推奨されるセキュリティのベストプラクティス](http://www.phptherightway.com/#security)に従ってください。決してパスワードをプレーンテキストとして保存しないでください。 – tadman

+1

**警告**:PHPを学んでいるだけの方は、[mysql_query'](http://php.net/manual/en/function.mysql-query.php)インタフェースを使用しないでください。それはPHP 7で削除されたのでとてもひどいと危険です。[PDOのようなものは学ぶのが難しくない](http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps -pdo-for-database-access /)と[PHP The Right Way](http://www.phptherightway.com/)のようなガイドがベストプラクティスを説明しています。あなたのユーザーパラメータは**適切にエスケープされていません**(http://bobby-tables.com/php)、悪用可能な[SQLインジェクションバグ](http://bobby-tables.com/)があります。 – tadman

答えて

0

             
  
 <html> 
 
     <head> 
 
     <TITLE>Welcome</TITLE> 
 
     </head> 
 
     <body> 
 
     <form action="checklogin.php" method="POST"> 
 
     <div> 
 
     <strong>Username:</strong><input type="text" name="username"><br/> 
 
     <strong>Password:</strong><input type="password" name="password" ><br/> 
 
     <input type="submit" name="submit" value="Submit"><br/> 
 
     </div> 
 
     </form> 
 
      </body> 
 
     </html>
<?php 
 
//code for checklogin.php file 
 
      session_start(); 
 
      echo "Hello world!"; 
 
      include('sql_connect.db.php'); 
 
     
 
      $uname=$_POST['username']; 
 
      $pass=$_POST['password']; 
 
      
 
      $result = mysql_query("SELECT * FROM users WHERE username=$uname"); 
 
      $row=mysql_fetch_array($result); 
 
      $flag=0; 
 
      if($row) 
 
      $usp=$row['password']; 
 
      if (pass==usp){ 
 
      $_SESSION['login_user'] = $uname; 
 
      header("location: success.php"); 
 
      }else { 
 
       $error = "Your Login Name or Password is invalid"; 
 
       } 
 
      ?>