新聞中心
怎么實(shí)現(xiàn)php兩個頁面之間傳遞數(shù)據(jù)
使用表單來傳遞,_post它在php只能獲取由表單的 method="post" 時它才能接受到數(shù)據(jù),
站在用戶的角度思考問題,與客戶深入溝通,找到定陶網(wǎng)站設(shè)計(jì)與定陶網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個性化、用戶體驗(yàn)好的作品,建站類型包括:網(wǎng)站制作、網(wǎng)站設(shè)計(jì)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、域名與空間、虛擬主機(jī)、企業(yè)郵箱。業(yè)務(wù)覆蓋定陶地區(qū)。
如下代碼:
form?id="form1"?name="form1"?method="get"?action=""
label
input?type="text"?name="cn"?value='獲取到我了'?/
/label
/forma.php頁面
?
if(?$_post?)
{
echo?$_post['cn'];
}
else
{
echo?'沒有獲取到值';
}
?
PHP與PHP數(shù)據(jù)傳輸
這需要用ajax來實(shí)現(xiàn)
index.php
html
titlephp+jquery+ajax+json簡單小例子/title
?php
header("Content-Type:text/html;charset=utf-8");
?
head
script?type="text/javascript"?src="
script?type="text/javascript"
$(function()?{
$("#subbtn").click(function()?{
var?params?=?$("input").serialize();
var?url?=?"1.php";
$.ajax({
type:?"post",
url:?url,
dataType:?"json",
data:?params,
success:?function(msg){
var?backdata?=?"您提交的姓名為:"?+?msg.name?+
"br?/?您提交的密碼為:"?+?msg.password;
$("#backdata").html(backdata);
$("#backdata").css({color:?"green"});
}
});
});
});
/script
/head
body
plabel?for="name"姓名:/label
input?id="name"?name="name"?type="text"?/
/p
plabel?for="password"密碼:/label
input?id="password"?name="password"?type="password"?/
/p
span?id="backdata"/span
pinput?id="subbtn"?type="button"?value="提交數(shù)據(jù)"?//p
/body
/html
1.php代碼:
?php
//接收數(shù)據(jù)-處理數(shù)據(jù)-返回?cái)?shù)據(jù)
echo?json_encode($_POST);
?
php文件與php文件之間如何傳遞數(shù)據(jù)?
通過session來儲存
?php
session_start();
$_SESSION['username'] = "userName";
?
在其它頁面直接取出就行了
?
session_start();
echo?$_SESSION['username'];
?
通過url傳向其它頁面?zhèn)鬟f參數(shù)
other.php?user=xxx
?或在php重定向到其它頁面時
$username = "xxx";
$home_url = 'logIn.php?user='.$username;
header('Location:'.$home_url);
其它頁面用$_GET["user"]來接收
3.通過表單向其它頁面?zhèn)魉蛥?shù)
其它頁面用$_POST["user"]來接收
文章標(biāo)題:php之間傳輸數(shù)據(jù) php文件傳輸
網(wǎng)頁路徑:http://www.ef60e0e.cn/article/dooddcg.html