Home > Backend Development > PHP Tutorial > Disadvantages of using htmlspecialchars to encode special characters in PHP

Disadvantages of using htmlspecialchars to encode special characters in PHP

WBOY
Release: 2016-07-29 08:51:28
Original
1053 people have browsed it

When using htmlspecialchars to encode special characters (&, ', ", <, >) in the parameters passed by the form (due to the need for security filtering when inserting into the database), the following problems will occur.

If the user uploads a file with special characters, such as ', the following problem will occur when the file name is saved to the database


Disadvantages of using htmlspecialchars to encode special characters in PHP

If your server-side PHP code passes $_GET[' id'] indirectly to obtain its file name, and then transfer it to the client by name.

<?php    
$name = mysql_query('SELECT name FROM accessories');//通过 ID 获取文件名
//......获取文件......
$file_path = ROOT_PATH . '/uploads/accessories/'. $name;
header ( 'Content-Disposition: attachment; filename=' . urlencode ( $name ) );
header ( 'Content-type: application/octet-stream;' );
header ( 'Content-Length: ' . filesize ( $file_path ) );
readfile ( $file_path );
exit ();
?>?
Copy after login

Then the following file name error will occur when downloading


Disadvantages of using htmlspecialchars to encode special characters in PHPPersonal homepage:
https://plus.google.com/+sherlockwang/posts

Original link: http://woqilin.blogspot.com/2012/10/php-htmlspecialchars.html

The above has introduced the disadvantages of using htmlspecialchars to encode special characters in PHP, including the relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template