开发者

Encode HTML Form POST Data

What is the best way to encode text posted to a PHP script from an HTML form so that special characters, i.e. "#'@ etc are not modified in anyway. My thoughts were to uuencode the data with JavaScript at form submission and then base64_decode() 开发者_运维技巧it in PHP, or escape the text with js then urldecode() with PHP, or is there another way?


You do that very easy by setting an appropriate codepage like UTF-8:

<form action="/cgi-bin/script.php" method="post" accept-charset="UTF-8">
<!-- Form elements go here -->
</form>

I would always try do do stuff without client-side scripting first, because of compatibility.


I know this is a very old question but this is what you maybe were looking for:

<form action="/cgi-bin/script.php" method="post" enctype="application/x-www-form-urlencoded">
<!-- Form elements go here -->
</form>

The weird thing is that the enctype="application/x-www-form-urlencoded" should be the default - but something happens when I don't use it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜