POST GET 差異
POST 表單傳輸的一種方式,優點是非明碼傳輸無長度限制 重要的資料請使用此方式 (如:帳/密)
GET 表單傳輸的一種方式,優點是所見即得(誤)是傳什都東西都在網址上面,相較下較不安全 長度限制依不同瀏覽器網址列長度而定 不重要的可使用此方式 (如:分頁目前頁數 查詢參數)
基本表單格式:
表單傳送使用POST方式
[html]
<form id="form1" method="POST" action="postfrom.php">
姓名:<input name="name" type="text" />
年齡:<input name="age" type="text" />
<input type="submit" value="送出" />
</form>
[/html]
表單傳送使用GET方式
[html]
<form id="form1" method="GET" action="getfrom.php">
姓名:<input name="name" type="text" />
年齡:<input name="age" type="text" />
<input type="submit" value="送出" />
</form>
[/html]
註:你也可以這樣用
getfrom.php?name=jeff&age=18
?後面接get參數
參數名稱=參數值
接收POST參數 (postfrom.php)
[php]
<?php
$name=isset($_POST[‘name’]?$_POST[‘name’]:”);
$age=isset($_POST[‘age’]?$_POST[‘age’]:”);
//isset() 這函式的功能是去判斷是否存在此變數
echo $name.’今年’.$age.’歲’;
?>
[/php]
接收GET參數 (getfrom.php)
[php]
<?php
$name=isset($_GET[‘name’]?$_GET[‘name’]:”);
$age=isset($_GET[‘age’]?$_GET[‘age’]:”);
//isset() 這函式的功能是去判斷是否存在此變數
echo $name.’今年’.$age.’歲’;
?>
[/php]
回PHP教學目錄
阿麥斯音樂棒棒糖
3M 日本原裝進口 速效型 防水噴霧 170ml 衣物 鞋子 皮革 透氣 防水 團購
水壺背袋 水壺網袋 水瓶袋 多色可選 戶外郊遊 登山野餐 可放手機 水壺背帶
垃圾桶 家用 客廳 臥室 辦公室 衛生間 大容量 高顏值 創意 收納 垃圾