Jump to content

[SOLVED] htmlentities() and $_POST


Omzy

Recommended Posts

I POST the following as a hidden variable in my first form:

 

echo '<input type="hidden" name="username" value="'.htmlentities($_POST['username']).'"/>';

 

This takes you to the second form, which has the following:

 

echo '<input type="hidden" name="username" value="'.$_POST['username'].'"/>';

 

I assume it would carry forward the exact value that has been POSTed. I tested this using a string with an 'ampersand' (&) and in the first form it works as expected, by converting '&' into '&'.

 

However in my second form it seems to convert it back to '&'. Is this the default behaviour/do I have to re-convert it using htmlentities() in my second form, or have I missed something out?

Link to comment
https://forums.phpfreaks.com/topic/169663-solved-htmlentities-and-_post/
Share on other sites

It doesn't change the value, it returns a new value. Few of the functions have what you call a side effect.

 

Edit: I misread your topic, but you still have to do it each time. It doesn't mean that the value will be &, but it has to be like that in the HTML source in order to be valid. The posted value will still be &.

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.