php獲取傳來的數(shù)據(jù) php傳輸數(shù)據(jù)的方式

php獲取post數(shù)據(jù)

方法1、最常見的方法是:$_post['fieldname'];

創(chuàng)新互聯(lián)公司堅持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:成都做網(wǎng)站、成都網(wǎng)站設(shè)計、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時代的德清網(wǎng)站設(shè)計、移動媒體設(shè)計的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!

說明:只能接收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)制文件流也可以。

所以用方法二是最保險的方法

方法3、$globals['http_raw_post_data'];

說明:

總是產(chǎn)生

$http_raw_post_data

變量包含有原始的

post

數(shù)據(jù)。

此變量僅在碰到未識別

mime

類型的數(shù)據(jù)時產(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ù)時

必須顯式示指明content-type:

application/x-www-form-urlencoded,post的數(shù)據(jù)才會存放到

$globals['http_raw_post_data']中

PHP怎么獲取傳送過來數(shù)據(jù)的來源

php有個超全局變量可以滿足你的需求,$_SERVER是個很強(qiáng)大的超全局變量,$_SERVER[‘HTTP_REFERER’]這個可以獲取域名,$_SERVER["REMOTE_ADDR"]這個可以獲取ip

PHP 獲取網(wǎng)頁中用戶輸入的數(shù)據(jù)的函數(shù)是什么?

index.html //提交數(shù)據(jù)

form action="get.php" method="post"

input name="data" type="text" /

input type="submit" name="sub" value="提交"/

/form

get.php//獲取數(shù)據(jù)

if(isset($_POST["sub"]{ //如果提交了表單

$data=$_POST["data"]; //將傳遞過來的數(shù)據(jù)賦給$data

echo $data; //輸出獲得的數(shù)據(jù)

}

php 怎么接收前端傳來的json數(shù)據(jù)

?php

header("Content-type:text/html;charset=utf-8");

if($_POST){

$d = $_POST['data'];//這里獲取的直接就是數(shù)組了,不需要用到j(luò)son_decode

echo $d['doing'];

//print_r($d);

exit;

}

?

script src="js/jquery-1.7.2.min.js"/script

script type="text/javascript"

$(document).ready(function() {

$("#xx").click(function(){

var url = "test.php";

var str ="{'doing':'createvote','type':'type','num':'num','votetheme':'votetheme','creater':'loginname'}";//json格式字符串

var data = eval('('+str+')');//轉(zhuǎn)換成數(shù)組對象,不加這步,那么PHP獲取的是字符串。

$.post(url, {'data': data}, function(res) {//注意jquery的$.post的第2個參數(shù)必須是鍵值對形式

alert(res);

});

});

});

/script

input id="xx" type="button" value="點(diǎn)擊"

PHP怎么獲取非form表單傳來的post數(shù)據(jù)

首先你一點(diǎn)提交,form里面會指定提交到某個頁面,form標(biāo)簽里面有一個屬性是指定提交的方式method="get"或者method="post",如果是用get提交,到下個頁面用$_GET["XXX"]; 來接收,如果是用post提交,到下個頁面用$_POST["XXX"];接收。你可以試一下用echo $_POST["XXX"];打印出來看看。如果表單提交的是多選按鈕值,那就需要用數(shù)組方式才能穿到下個頁面

文章標(biāo)題:php獲取傳來的數(shù)據(jù) php傳輸數(shù)據(jù)的方式
地址分享:http://muchs.cn/article18/doccedp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)網(wǎng)站建設(shè)、網(wǎng)站建設(shè)、Google、電子商務(wù)、網(wǎng)站內(nèi)鏈、商城網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站建設(shè)網(wǎng)站維護(hù)公司