2012-06-16 4 views
-2

이 포럼에 다른 문제가 있습니다. HTML을 게시하지 않고 모든 것이 잘 작동합니다.포럼에서 MySQL의 HTML을 표시하지 않습니다.

내가 스레드를 게시하지 않고 스레드를 게시하면 스레드보기에 표시되지만 HTML, 굵게 등으로 게시물을 게시하면 전혀 표시되지 않습니다.

을 Heres 후 파일 여기

<?php 

include "connect.php"; //connection string 

if(isset($_POST['submit'])) 

{ 

    $name=$_POST['name']; 

    $yourpost=$_POST['yourpost']; 

    $subject=$_POST['subject']; 

    if(strlen($name)<1) 

    { 

     print "You did not type in a name."; //no name entered 

    } 

    else if(strlen($yourpost)<1) 

    { 

     print "You did not type in a post."; //no post entered 

    } 

    else if(strlen($subject)<1) 

    { 

     print "You did not enter a subject."; //no subject entered 

    } 

    else 

    { 

     $thedate=date("U"); //get unix timestamp 

     $displaytime=date("F j, Y, g:i a"); 

     //we now strip HTML injections 

     $subject=strip_tags($subject); 

     $name=strip_tags($name); 

     $yourpost=strip_tags($yourpost); 

     $insertpost="INSERT INTO forumtutorial_posts(author,title,post,showtime,realtime,lastposter) values('$name','$subject','$yourpost','$displaytime','$thedate','$name')"; 

     mysql_query($insertpost) or die("Could not insert post"); //insert post 

     print "Message posted, go back to <A href='index.php'>Forum</a>."; 

    } 



} 

else 

{ 

    print "<form action='post.php' method='post'>"; 

    print '<input type="hidden" name="name" value="' . $_SESSION[usr_name] . '" size="20"><br>'; 

    print "Topic title:<br>"; 

    print "<input type='text' name='subject' size='20'><br>"; 

    print "Your message:<br>"; 

    print "<textarea name='yourpost' rows='5' cols='40' id='new_thread'></textarea><br>"; 

    print "<input type='submit' name='submit' value='submit'></form>"; 



} 

?> 
<script language="JavaScript"> 
    generate_wysiwyg('new_thread'); 
</script> 

그리고 스레드보기

<?php 

include "connect.php"; //mysql db connection here 

$id=$_GET['id']; 

$gettopic="SELECT * from forumtutorial_posts where postid='$id'"; 

$gettopic2=mysql_query($gettopic) or die("Could not get topic"); 

$gettopic3=mysql_fetch_array($gettopic2); 

print "<div id='left'>"; 

print "<div id='navi-body'>"; 

print "<a href='index.php'>Back to main forum</a> <a href='post.php'>New Topic</a> <A href='reply.php?id=$id'>Reply</a>"; 

print "</div>"; 

print "<div class='content'>"; 

print "<div class='content-header yellow'>$gettopic3[title]</div>"; 

print "<div class='content-mid'>"; 

$message=strip_tags($gettopic3['post']); 

$message=nl2br($message); 

print "$message"; 

print "<br /><br />"; 

print "Posted by: $gettopic3[author] Created at: $gettopic3[showtime]"; 

print "</div>"; 

print "<div class='content-footer'></div>"; 

print "</div>"; 

$getreplies="Select * from forumtutorial_posts where parentid='$id' order by postid desc"; //getting replies 

$getreplies2=mysql_query($getreplies) or die("Could not get replies"); 

while($getreplies3=mysql_fetch_array($getreplies2)) 

{ 

    print "<div class='content'>"; 

    print "<div class='content-header yellow'>$getreplies3[author] replied at $getreplies3[showtime]</div>"; 

    print "<div class='content-mid'>"; 

    $message=strip_tags($getreplies3['post']); 

    $message=nl2br($message); 

    print "$message"; 

    print "</div>"; 

    print "<div class='content-footer'></div>"; 

    print "</div>"; 

} 

print " "; 



?> 

나는 그것이 HTML 및 비 HTML을 보여주고 싶은에게 있습니다.

+0

게시되는 내용과 반환되는 내용을 MySQL과 PHP에서 모두 보여주십시오. –

+0

안녕하세요 Blowski, mysql에서 "게시물"비트가 비어 있지만 다른 모든 것들이 정확하게 채워집니다. – NickkN

+0

그리고 지금은 입력 내용이 완전히 안전하지 않으므로 이것이 단지 더미 코드가되기를 바랍니다. PDO를 실제로 조사해야합니다. –

답변

1

.. 그러나 문자열 (게시)에서 HTML 또는 PHP 태그를 줄무는 strip_tags() 함수가 있습니다.

$message=strip_tags($getreplies3['post']); 

이 기능의 두 번째 부분을 사용하고 허용하려는 태그에 대한 추가 매개 변수를 추가 할 수 있습니다. (등, 기울임 꼴, BOLD처럼) 나는 내가 맞다 희망

$message_with_some_html = strip_tags($getreplies3['post'], '<strong><em>'); 

는, 클라이언트 입력을 사용하기 전에 또한

: 당신이 $ _POST 변수를 소독 할 수 있습니다 ... PHP의 문서를 확인하십시오 htmlentities()와 가능한 정규식을 사용하여 공격을 걸러 낼 수 있습니다.

+0

밀라노 모든 HTML을 허용하고 싶습니다.이 점에 대해 이해할 수있는 자습서가 있습니까? S – NickkN

+0

안녕하세요, 고객의 입력에 맞게 tinyMCE를 구현하고 싶을 수 있습니다. (http://www.tinymce.com /) 또한 몇 가지 추가 사양을 필터링하는 방법에 대한 좋은 조언을 보려면이 게시물을 확인하십시오. chars. : http://stackoverflow.com/questions/1225472/validation-detected-dangerous-client-input-post-from-tinymce-in-asp-net – Milan

+0

좀 더 구체적으로 페이지를 사용하고 있습니까? – Milan

관련 문제