2016-10-24 6 views
0

으로 호출하십시오. SQL 삽입을 방지하기 위해 로그인 양식에서 입력을 이스케이프 처리하려고합니다. 하지만 난 얻을 오류로 :치명적인 오류 : 알려지지 않은 오류 : 정의되지 않은 함수 mysql_real_escape_string()을

Fatal error: Uncaught Error: Call to undefined function mysql_real_escape_string() in F:\Apache24\htdocs\Site1\user\login.php:17 Stack trace: #0 {main} thrown in F:\Apache24\htdocs\Site1\user\login.php on line 17

아직 소독 또는 난 아직 페이지를 구축하고 있기 때문에 사용자의 입력을 검증하지 않은하지만 난 제대로 데이터베이스에 연결되어있는 경우 테스트하고 싶었다.

<!DOCTYPE html> 
<?php 
    include('../includes/pdo_connect.php'); 
    $expiry = time()+60*60*24; 
    if(!setcookie('userdata[user_id]', $user_id, $expiry, '', '', '', TRUE)){ 
     echo "<script>alert('could not set cookie');</script>"; 
    } 
?> 
<html> 
<head> 
    <title>Login</title> 
    <link rel="stylesheet" type="text/css" href="../styles/login_style.css"> 
    <?php 
     global $con; 

     if(isset($_POST['login_ok'])){ 
      $email = mysql_real_escape_string($_POST['email']); 
      $pass = mysql_real_escape_string($_POST['password']); 

      try{ 
       $query = "select * from user where user_email=':email' and password=':pass'"; 
       $stmt = $con->prepare(); 

       $stmt->bindParam(':email', $email, PDO::PARAM_STR); 
       $stmt->bindParam(':pass', $pass, PDO::PARAM_STR); 

       $stmt->execute(); 

       $result = $stmt->fetchAll(); 

       foreach($result as $row) { 
        $user_id = $row['user_id']; 
        //$user_first_name = $row['user_first_name']; 
        header("Location:profile.php"); 
       } 

      } catch(PDOException $e){ 
       echo "Error: ".$e->getMessage(); 
      } 
     } 
    ?> 
</head> 
<body> 
    <div class="wrapper"> 
     <header> 

     </header> 
     <div class="form_div"> 
      <div class="form"> 
       <form id="register_form" method="post" action="" autocomplete="autocomplete"> 
        <table> 
         <tr> 
          <td id="label">Email: </td> 
          <td id="input"><input type="text" name="email" required="required" id="input_box"></td> 
         </tr> 
          <td id="label">Password: </td> 
          <td id="input"><input type="password" name="password" id="input_box"></td> 
         </tr> 
         <tr id="button_row"> 
          <td colspan="2"><input type="reset" value="Reset" id="button"> 
          <input type="submit" value="Login" id="button" name="login_ok"></td> 
         </tr> 
        </table> 
       </form> 
      </div> 
     </div> 
    </div> 
</body> 
</html> 
+1

당신은 mysql_real_escape_string을 필요로하지 않으므로 바인드를 사용하기 때문에 그냥 제거하십시오 – nospor

+0

$ email = mysql_real_escape_string ($ _ POST [ 'email']); $ pass = mysql_real_escape_string ($ _ POST [ 'password']); mysql_real_escape_string을 제거하십시오 –

+0

@nospor 제안을 보내 주셔서 감사합니다. 그러나 나는 무엇이 잘못되었는지 알고 싶다. – Vinay

답변

2

mysql_ API는 현재 무효이며, (PDO에 찬성하고 mysqli_에) PHP에서 제거되었습니다 : 이것은 로그인 페이지의 코드입니다.

$stmt->bindParam(':email', $email, PDO::PARAM_STR);가 SQL 인젝션 방어하기에 충분하다 : 당신은 당신이 이미 SQL 인젝션, 방어하기 위해 PDO 방법을 사용한다, 그래서

하기는하지만 PDO를 사용하고 있습니다.

관련 문제