php直接用全局變量$_POST來接收post參數(shù)
創(chuàng)新互聯(lián)公司網(wǎng)站建設(shè)公司一直秉承“誠信做人,踏實(shí)做事”的原則,不欺瞞客戶,是我們最起碼的底線! 以服務(wù)為基礎(chǔ),以質(zhì)量求生存,以技術(shù)求發(fā)展,成交一個(gè)客戶多一個(gè)朋友!專注中小微企業(yè)官網(wǎng)定制,成都做網(wǎng)站、成都網(wǎng)站建設(shè),塑造企業(yè)網(wǎng)絡(luò)形象打造互聯(lián)網(wǎng)企業(yè)效應(yīng)。
比如:前端input name ="username" value="123" type="text"/
參數(shù)username通過post傳參數(shù)到服務(wù)器,php以$_POST['username']來接收
form表單demo:task.html
fieldset id="setFiled"
legend發(fā)布任務(wù)/legend
form action="registr.php" method="post" id="steForm"
label任務(wù)類型:/labelbr
input type="text" name="type"? id="taskType" placeholder="請選擇任務(wù)類型"/br
label酬nbsp;nbsp;金:/labelbr
input type="number" name="money" id="forMoney" min="1" max="1000"/label元/labelbr
label截止時(shí)間:/labelbr
input type="datetime" name="time" id="timeSubmit"/span data-year="" data-month="" data-date="" id="showDate"/spanbr
label詳細(xì)描述:/labelbr
textarea maxlength="512" name="textAray" id="msgArea"/textareabr
input type="submit" name="subMit" id="forSub" value="點(diǎn)擊發(fā)布" /
/form
擴(kuò)展資料
php接收POST數(shù)據(jù)的三種方式
1、$_POST 方式接受數(shù)據(jù)
$_POST 方式是由通過HTTP的POST方法傳遞過來的數(shù)據(jù)組成的數(shù)組,是一個(gè)自動(dòng)全局變量。
注:只能接收Content-Type:application/x-www-form-urlencode提交的數(shù)據(jù)。也就是只能接收表單過來的數(shù)據(jù)。
2、GLOBLES[‘HTTP_RAW_POST_DATA’]
如果訪問原始POST數(shù)據(jù)不是php能夠識別的文檔類型,比如:text/xml 或者soap等等,可以用$GLOBLES[‘HTTP_RAW_POST_DATA’]來接收,$HTTP_RAW_POST_DATA變量包含有原始POST數(shù)據(jù)。此變量僅在碰到未識別的MIME數(shù)據(jù)時(shí)產(chǎn)生。
注:$HTTP_RAW_POST_DATA對于enctype=”multipart/form-data”表單數(shù)據(jù)不可用,也就是說使用$HTTP_RAW_POST_DATA無法接受網(wǎng)頁表單post過來的數(shù)據(jù)。
3、file_get_contents(“php://input”);
如果訪問原始POST數(shù)據(jù),更好的方法是使用file_get_content(“php://input”);對于未指定Content-Type的POST數(shù)據(jù),可以使用該方法讀取POST原始數(shù)據(jù),包括二進(jìn)制流也可以和$HTTP_RAW_POST_DATA比起來。它帶來的生存眼里更小,并且不需要任何特殊的php.ini設(shè)置。
注:php://input不能用于 enctype=”multipart/form-data”
例如:$postStr = file_get_contents("php://input"); //獲取POST數(shù)據(jù)
方法1、最常見的方法是:$_post['fieldname'];
說明:只能接收content-type:
application/x-www-form-urlencoded提交的數(shù)據(jù)
解釋:也就是表單post過來的數(shù)據(jù)
方法2、file_get_contents("php://input");
說明:
允許讀取
post
的原始數(shù)據(jù)。
和
$http_raw_post_data
比起來,它給內(nèi)存帶來的壓力較小,并且不需要任何特殊的
php.ini
設(shè)置。
php://input
不能用于
enctype="multipart/form-data"。
解釋:
對于未指定
content-type
的post數(shù)據(jù),則可以使用file_get_contents(“php://input”);來獲取原始數(shù)據(jù)。
事實(shí)上,用php接收post的任何數(shù)據(jù)都可以使用本方法。而不用考慮content-type,包括二進(jìn)制文件流也可以。
所以用方法二是最保險(xiǎn)的方法
方法3、$globals['http_raw_post_data'];
說明:
總是產(chǎn)生
$http_raw_post_data
變量包含有原始的
post
數(shù)據(jù)。
此變量僅在碰到未識別
mime
類型的數(shù)據(jù)時(shí)產(chǎn)生。
$http_raw_post_data
對于
enctype="multipart/form-data"
表單數(shù)據(jù)不可用
如果post過來的數(shù)據(jù)不是php能夠識別的,可以用
$globals['http_raw_post_data']來接收,
比如
text/xml
或者
soap
等等
解釋:
$globals['http_raw_post_data']存放的是post過來的原始數(shù)據(jù)。
$_post或$_request存放的是
php以key=value的形式格式化以后的數(shù)據(jù)。
但$globals['http_raw_post_data']中是否保存post過來的數(shù)據(jù)取決于centent-type的設(shè)置,即post數(shù)據(jù)時(shí)
必須顯式示指明content-type:
application/x-www-form-urlencoded,post的數(shù)據(jù)才會(huì)存放到
$globals['http_raw_post_data']中
1、直接獲取所有傳遞
$username = $_REQUEST['username'];
2、只獲取POST提交的
$username = $_POST['username']
新聞名稱:php所有post數(shù)據(jù) php中的post
URL鏈接:http://m.kartarina.com/article26/dodsjjg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)頁設(shè)計(jì)公司、靜態(tài)網(wǎng)站、微信小程序、ChatGPT、網(wǎng)站設(shè)計(jì)公司、企業(yè)網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)