国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

PHP ?? ??? ??

PHP ??? ?? ?? ??? ???? ???.

? ???? ??? ??? ???? ?? PHP ?? ???? ?? ??? ?????.


? ?? ??? HTML ???? ?? ?? ??? ???? ????. ??? ??? ??, ??? ??? ????? ? , ?? ??:

Instance

<!DOCTYPE HTML>
 <html>
 <head>
     <meta charset="utf-8">
     <title>PHP.cn</title>
 </head>
 <body>
 <h2>PHP 表單驗(yàn)證實(shí)例</h2>
 <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> 
    名字: <input type="text" name="name" value="">
     <br>
     E-mail: <input type="text" name="email" value="">
     <br>
     網(wǎng)址: <input type="text" name="website" value="">
     <br>
     備注: <textarea name="comment" rows="5" cols="40"></textarea>
     <br>
     性別:
     <input type="radio" name="gender"  value="female">女
     <input type="radio" name="gender"  value="male">男
     <br>
     <input type="submit" name="submit" value="提交">
 </form>
 </body>
 </html>

???? ?? ??:

5.png

? ?? ??? ?? ??? ??? ????.

          字段        驗(yàn)證規(guī)則
    名字必須。 +只能包含字母和空格
    E-mail必須。 + 必須是一個(gè)有效的電子郵件地址(包含'@'和'.')
    網(wǎng)址可選。如果存在,它必須包含一個(gè)有效的URL
    備注可選。 多行輸入字段(文本域)
??
    性別必須。 必須選擇一個(gè)
??? ?? ??
???????. +??? ??? ??? ? ????
??? URL????. ?? ?? ??? URL? ???? ???.
????? ??

'??', '???', '????' ??? ??? ?? ????, '??' ??? ??? ?? ??? ?????.

HTML ??? ??? ????.

??: <?? ??= " text" name="name" value="">
???: <input type="text" name="email" value="">
????: <input type= " text" name="website" value="">
??: <textarea name="comment"rows="5" cols="40"></textarea>


??? ??

"??" ??? ??? ?????.

HTML ??? ??? ????.

??:
<?? ??= " radio" name="gender" value="female">??
<input type="radio" name="gender" value="??">??


?? ??

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? ???? ?? ???? ??? ???? CSS??? ?? XSS(?? ??? ????)? ??? ? ????. ? ?? XSS? ???? ???? ?? ???? ?? ? ???? ????? ? ????? ??? ? ????.

?? ??? "test_form.php"?? ???? ??? ?????.

< ;form method="post" action="<?php echo $_SERVER["PHP_SELF"];?>">

?? URL? ???? ?? ?? "test_form.php"? ?????. ? ??? ??? ?? ?????.

<form method=" post " action="test_form.php">

?????.

??? ???? ???? ?? ???? ?? ??? ????? ?? ?????.

http://m.miracleart.cn/test_form.php/% 22 %3E%3Cscript%3Ealert('hacked')%3C/script%3E


? URL? ?? ??? ?? ???? ?????.

<form method="post" action="test_form.php/"><script>alert('hacked')</script>


??? ???? ??? ?????, ?? ??? ???????. ? Javascript ??? ???? ??? ? ?????(????? ?? ??? ???). ?? ??? PHP_SELF ??? ??? ??? ? ??? ???? ??? ????.

?? ?? JavaScript ??? <script> ??? ??? ? ????! ??? ?? ??? ???? ?? ??? ????? ? ????. ?? ??? ?? ??? ????? ???? ?? ???? ?? ? ????.


$_SERVER["PHP_SELF"] ??? ???? ??? ??????

$ _SERVER ["PHP_SELF"]? htmlspecialchars() ??? ???? ?? ? ????.

? ??? ??? ????:

<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]) ;?>">

htmlspecialchars() ?? ??? ?? ??? HTML ???? ?????. ?? ???? PHP_SELF ??? ????? ?? ??? ??? ?? ?????.

<form method="post" action="test_form.php/"> <script> ??('???')</script>">

? ???? ???? ?????!


PHP? ?? ?? ??? ??? ??

?? ?? ?? ? ?? PHP? htmlspecialchars() ??? ?? ?? ??? ???? ????.

htmlspecialchars() ??? ??? ? ???? ??? ??? ??? ????? ??:

<script>location.href('http :/ /www.hacked.com')</script>

- ??? ??? ?? ????? ??? ????? ???? ????.

<script>location.href('http://www.hacked.com')</script>

?? ? ??? ???? ???? ????? ???? ?????.

???? ??? ???? ?? ? ?? ??? ? ???? ???.

1. (PHP Trim() ??? ??) ??? ?? ????? ???? ??(?? ??)? ?????. , ?, ? ??)

2. (PHP ??????() ??? ??) ??? ?? ????? ???? ??()

???? ?? ??? ????(??? ???? ???? ?? ??). ?? ????? ????).

?? ??? test_input()?? ??????.

?? test_input() ??? ?? ? $_POST ??? ??? ? ????. ????? ??? ????.

?

<!DOCTYPE HTML>
 <html>
 <head>
     <meta charset="utf-8">
     <title>PHP中文網(wǎng)(php.cn)</title>
 </head>
 <body>
 
 <?php
 // 定義變量并默認(rèn)設(shè)置為空值
 $name = $email = $gender = $comment = $website = "";
 
 if ($_SERVER["REQUEST_METHOD"] == "POST")
 {
     $name = test_input($_POST["name"]);
     $email = test_input($_POST["email"]);
     $website = test_input($_POST["website"]);
     $comment = test_input($_POST["comment"]);
     $gender = test_input($_POST["gender"]);
 }
 
 function test_input($data)
 {
     $data = trim($data);
     $data = stripslashes($data);
     $data = htmlspecialchars($data);
     return $data;
 }
 ?>
 
 <h2>PHP 表單驗(yàn)證實(shí)例</h2>
 <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
     名字: <input type="text" name="name">
     <br><br>
     E-mail: <input type="text" name="email">
     <br><br>
     網(wǎng)址: <input type="text" name="website">
     <br><br>
     備注: <textarea name="comment" rows="5" cols="40"></textarea>
     <br><br>
     性別:
     <input type="radio" name="gender" value="female">女
     <input type="radio" name="gender" value="male">男
     <br><br>
     <input type="submit" name="submit" value="提交">
 </form>
 
 <?php
 echo "<h2>您輸入的內(nèi)容是:</h2>";
 echo $name;
 echo "<br>";
 echo $email;
 echo "<br>";
 echo $website;
 echo "<br>";
 echo $comment;
 echo "<br>";
 echo $gender;
 ?>
 
 </body>

????? ???? ?????


??: ? ????? ??? ? $_SERVER["REQUEST_METHOD"]? ???? ??? ?????? ?????. REQUEST_METHOD? POST?? ??? ???? ???? ???? ?????. ??? ???? ??? ??? ??? ???? ???? ?????.

? ???? ????? ??? ??????, ???? ??? ???? ???? ??? ????? ??? ? ????.


?? ???? ???? ??? ???? ???? ???? ??? ?????.



???? ??
||
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title>PHP.cn</title> </head> <body> <h2>PHP 表單驗(yàn)證實(shí)例</h2> <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> 名字: <input type="text" name="name" value=""> <br> E-mail: <input type="text" name="email" value=""> <br> 網(wǎng)址: <input type="text" name="website" value=""> <br> 備注: <textarea name="comment" rows="5" cols="40"></textarea> <br> 性別: <input type="radio" name="gender" value="female">女 <input type="radio" name="gender" value="male">男 <br> <input type="submit" name="submit" value="提交"> </form> </body> </html>