PHP ?? ??? ??
PHP ?? ??? ??
? ???? PHP? ???? ?????? ??? ?? ???? ???? ???? ??? ?????.
??? ?? ????? ????? ?? ??? ??? ???? ???? ???. ???? ??? ??? ? ???? ??? ??? ?????.
??? ??? ??????? ???? ?? ?? ?? ??? ?? ??? ???? ???. ???? ??? ???? ???? ?? ??? ?? ???? ???? ?? ??? ????? ???? ????. ??? ?? ???? ??? ?? ????? ?? ???? ?? ? ????. ???? ??? ?? ?? ? ?? ????.
PHP ??? ??? ?? ??? ???? ???.
? ???? ??? ??? ???? ?? PHP ?? ???? ?? ??? ?????. ??? ?? ??? ?? ??? ???? ???.
PHP ?? ??? ?? ?
? ????? ?? ??? ?? ??? ?????.
?? ?? ??? ?? HTML ??? ???????.
??? ??
??, ???, ????? ??? ?? ???? ?? ??? ??? ?????. HTML ??? ??? ????.
Name: <input type="text" name="name"> E-mail: <input type="text" name="email"> Website: <input type="text" name="website"> Comment: <textarea name="comment" rows="5" cols="40"></textarea>
??? ??
?? ??? ??? ????. ?? ?? ??? ???? ?? HTML ??? ??? ????.
Gender: <input type="radio" name="gender" value="female">Female <input type="radio" name="gender" value="male">Male
?? ??
??? HTML ??? ??? ????.
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
? ??? ???? ?? ???? method="post"? ?? ?????.
$_SERVER["PHP_SELF"] ??? ??????
$_SERVER["PHP_SELF"]? ?? ?? ?? ????? ?? ??? ???? ?? ?? ?????.
??? $_SERVER["PHP_SELF"]? ?? ???? ???? ?? ?? ???? ??? ??? ????. ??? ???? ???? ?? ????? ?? ??? ??? ?? ? ????.
htmlspecialchars() ??? ??????
htmlspecialchars() ??? ?? ??? HTML ???? ?????. ?? < ? >? ?? HTML ??? < ??? ?? ???? HTML ?? JavaScript ??? ??? ???? ??? ???? ?? ??? ? ????(?? ??? ???? ??).
PHP ?? ??? ?? ?? ??
$_SERVER["PHP_SELF"] ??? ??? ?? ??? ? ????!
????? PHP_SELF? ???? ?? ???? ??? ???? XSS(?? ??? ????)? ??? ? ????.
?: XSS(?? ??? ????)? ? ???????? ?? ???? ??? ??? ?? ??????. XSS? ???? ???? ?? ???? ?? ? ???? ????? ? ????? ??? ? ????.
"test_form.php"?? ???? ??? ?? ??? ??? ?????.
<form method="post" action= "< ?php echo $_SERVER["PHP_SELF"];?>">
?? ???? ?? ???? ?? URL? ???? "http://www. /test_form.php", ? ??? ??? ?? ?????:
<form method="post" action="test_form.php">
????? , ?? ?? ?????.
??? ???? ?? ???? ?? URL? ???? ??:
http://www.miracleart.cn/test_form.php/%22%3E%3Cscript%3Ealert(' php ')%3C/script%3E
? ?? ? ??? ??? ?? ?????.
<form method="post" action="test_form.php "/><script>alert('php')</script>
? ??? ????? ???? ??? ?????. ??? ???? ???? JavaScript ??? ?????(????? ?? ??? ?????). ??? PHP_SELF ??? ??? ??? ? ??? ???? ???? ??? ????.
<script> ???? ?? JavaScript ??? ??? ? ??? ?? ?????! ??? ???? ?? ??? ??? ????? ? ??? ?? ??? ?? ??? ?? ??? ????? ??? ??? ?? ???? ?? ??? ?? ??? ??? ? ????.
$_SERVER["PHP_SELF"]? ???? ?? ???? ??? ??????
htmlspecialchars() ??? ???? $_SERVER["PHP_SELF"]? ???? ?? ??? ? ????.
?? ??? ??? ????.
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" > ;
htmlspecialchars() ??? ?? ??? HTML ???? ?????. ?? ???? PHP_SELF ??? ????? ???? ??? ?? ??? ?????.
<form method="post" action="test_form.php/"><script>alert( 'php')< /script>">
??? ? ??? ?? ??? ????!
PHP? ?? ?? ??? ??
?? ?? ?? ? ?? PHP? htmlspecialchars() ??? ?? ?? ??? ???? ????.
htmlspecialchars() ??? ??? ? ???? ???? ??? ????? ?? ??:
< ;script>location.href('http://www.miracleart.cn')</script>
- ??? ?? ??? ??? ???? ????. ??? ?? ????? ??? ?????.
<script>location.href('http://www.miracleart.cn')</script>
?? ? ??? ???? e- ??? ????.
???? ??? ???? ?? ? ?? ??? ? ???? ???.
1. (PHP Trim() ??? ??) ??? ?? ????? ???? ??(?? ??)? ?????. , ?, ? ??)
2. (PHP ??????() ??? ??) ??? ?? ????? ???? ??()
???? ?? ??? ????(??? ???? ???? ?? ??). ?? ????? ????).
?? ??? test_input()?? ??????.