2014-01-10 2 views
0

의견 상자 양식이 실행 중이며 '을 사용하면 앞에 \이 생성됩니다. 예를 들어, "how 's"라고 쓰면, 데이터베이스에 게시하는 방법과 페이지에 표시 할 때 "how \ 's"로 표시됩니다. "body"텍스트를 표시 할 때 stripslashes 함수를 사용하고 있습니다.이 텍스트는 슬래시를 제거하기로되어 있다고 생각했습니다.스트립 슬래시 사용에도 불구하고 표시된 양식 텍스트에 슬래시가 표시됩니다.

제 서버가 PHP 5.3.6을 실행 중입니다. 내 데이터베이스에 메모 상자의 몸에서 텍스트를 작성하려면이 코드 조각을 사용하고

:

function mysql_prep($string) { 
    global $connection; 

    $escaped_string = mysqli_real_escape_string($connection, $string); 
    return $escaped_string; 
} 

사이드 :

$body = mysql_prep($_POST['body']); 

가 사용하는 기능이있다 참고 :이 질문에 대답 할 필요는 없지만, 텍스트 사용자가 해커, baddies 등으로부터 안전하게 입력하도록하기 위해 사용하고있는 기능입니다. 나는 그 일을 잘하고 있습니까, 아니면 제가 스스로 이슈에 개방적으로 남겨두고 있습니까?

이 내가 텍스트를 표시하는 데 사용하고 코드입니다 (때문에이 기능이 될 수있는이 슬래시 문제 외에) : 감사,

<div id="comments"> 
    <?php while($comment_text = mysqli_fetch_assoc($display_comments)) { ?> 
    <div class="comment" style="margin-bottom: 2em;"> 
     <div class="author"> 
      <b><?php echo htmlentities($comment_text["author"]); ?>:</b> 
     </div> 
     <div class="meta-info" style="font-size: 0.8em;"> 
      <?php echo datetime_to_text($comment_text["created"]); ?> 
     </div> 
     <div class="body"> 
      <?php echo stripslashes($comment_text["body"], '<strong><em><p>'); ?> 
     </div> 
    </div> 
    <?php } ?> 
    <?php if(empty($display_comments)) { echo "No Comments."; } ?> 
</div> 

어떤 도움이나 조언은 매우 감사합니다!

+1

'stripslashes()'이 보이지 않습니다. 나는'strip_tags()'만 보았습니다 (다른 것을합니다). –

+0

MySQLi 쿼리를 준비 할 때'mysqli_real_escape_string()'함수가 필요 없다. –

+0

oh dang, ur right @Gerald Schneider! 나는 그걸 꺼내서 스트립 슬래시를 대신 넣을거야? 내가 그 일을 함으로 뭔가를 망쳐 놓지 않는 한 ... – coolpup

답변

0

문제는 Magic Quotes이 켜져 있다는 것입니다. 당신은 재귀 적으로이 방법을 사용하여 모든 슬래시를 제거 할 수 있습니다

파일 magic_quotes_filter.php

<?php 

if (function_exists('set_magic_quotes_runtime') && get_magic_quotes_gpc()) { 

    function stripslashes_deep($value) { 
     $value = is_array($value) ? 
        array_map('stripslashes_deep', $value) : 
        stripslashes($value); 

     return $value; 
    } 

    $_POST = array_map('stripslashes_deep', $_POST); 
    $_GET = array_map('stripslashes_deep', $_GET); 
    $_COOKIE = array_map('stripslashes_deep', $_COOKIE); 
    $_REQUEST = array_map('stripslashes_deep', $_REQUEST); 
} 

그리고 저쪽 수 단순히 include('path/to/magic_quotes_filter.php') 당신이 요청 HTTP 변수를 다루는 곳.

귀하의 경우, 스크립트 상단에 포함 시키십시오.

관련 문제