Jump to content

Using $htmlentities correctly


nickd_101

Recommended Posts

Hi,
I'm attempting to "secure" a form on my website. I want to stop people using XSS and running rogue code in the forms. I'm attempting to use an example i found in a book:

<?php

    $clean = array();
    $html = array();

    /* Filter Input ($name, $comment) */

    $html['name'] = htmlentities($clean['name'], ENT_QUOTES, 'UTF-8');
    $html['comment'] = htmlentities($clean['comment'], ENT_QUOTES, 'UTF-8');

    echo "<p>{$html['name']} writes:<br />";
    echo "<blockquote>{$html['comment']}</blockquote></p>";

    ?>
this works allowing me to stop some html use but not all. Also it just leaves a blank space. Is there anyway to extract the text that the user attempts to post?
Link to comment
https://forums.phpfreaks.com/topic/19802-using-htmlentities-correctly/
Share on other sites

or use strip_tags() to remove html code completely

[code]<?php
$str = "This is <B>bold</B>";

echo $str . '<br />';
echo htmlentities($str) . '<br />';
echo strip_tags($str) . '<br />';

?>[/code]

-->
This is [B]bold[/B]
This is <B>bold</B>
This is bold

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.