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
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 &.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.