表單傳值有兩種方式分別為:
專注于為中小企業(yè)提供網(wǎng)站設(shè)計制作、網(wǎng)站建設(shè)服務(wù),電腦端+手機端+微信端的三站合一,更高效的管理,為中小企業(yè)天峨免費做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動了上千家企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設(shè)實現(xiàn)規(guī)模擴充和轉(zhuǎn)變。
get (通過URL進行傳值,這種方式并不安全);
post(封裝到一個post包中進行傳遞,比get安全,一般用這個)
下面我們用$_POST進行傳值:
?php
include("include/common.inc");
$title="表單處理頁";
include("include/header.inc");
if($_POST['name'] == null || $_POST['name'] == "你的名字")
echo "請輸入您的姓名";
else
{
echo "$name,您好,歡迎您的光臨!";
}
?
一、用file_get_contents以get方式獲取內(nèi)容,需要輸入內(nèi)容為:
1、?php
2、$url='';
3、$html=file_get_contents($url);
4、echo$html;
5、?
二、用file_get_contents函數(shù),以post方式獲取url,需要輸入內(nèi)容為
1、?php
2、$url='';
3、$data=array('foo'='bar');
4、$data=http_build_query($data);
5、$opts=array(
6、'http'=array(
7、?'method'='POST',
8、?'header'="Content-type:application/x-www-form-urlencoded\r\n".
9、??????????"Content-Length:".strlen($data)."\r\n",
10、?'content'=$data
11、)
12、);
13、$ctx=stream_context_create($opts);
14、$html=@file_get_contents($url,'',$ctx);
15、?
三、用fopen打開url,以get方式獲取內(nèi)容,需要輸入內(nèi)容為
1、?php
2、$fp=fopen($url,'r');
3、$header=stream_get_meta_data($fp);//獲取信息
4、while(!feof($fp)){
5、$result.=fgets($fp,1024);
6、}
7、echo"urlheader:{$header}br":
8、echo"urlbody:$result";
9、fclose($fp);
10、?
四、用fopen打開url,以post方式獲取內(nèi)容,需要輸入內(nèi)容為
1、?php
2、$data=array('foo2'='bar2','foo3'='bar3');
3、$data=http_build_query($data);
4、$opts=array(
5、'http'=array(
6、'method'='POST',
7、'header'="Content-type:application/x-www-form-urlencoded\r\nCookie:cook1=c3;cook2=c4\r\n".
8、"Content-Length:".strlen($data)."\r\n",
9、'content'=$data
10、)
11、);
12、$context=stream_context_create($opts);
13、$html=fopen(';id2=i4','rb',false,$context);
14、$w=fread($html,1024);
15、echo$w;
16、?
五、用fsockopen函數(shù)打開url,以get方式獲取完整的數(shù)據(jù),包括header和body,需要輸入內(nèi)容為
1、?php
2、functionget_url($url,$cookie=false)
3、{
4、$url=parse_url($url);
5、$query=$url[path]."?".$url[query];
6、echo"Query:".$query;
7、$fp=fsockopen($url[host],$url[port]?$url[port]:80,$errno,$errstr,30);
8、if(!$fp){
9、returnfalse;
10、}else{
11、$request="GET$queryHTTP/1.1\r\n";
12、$request.="Host:$url[host]\r\n";
13、$request.="Connection:Close\r\n";
14、if($cookie)$request.="Cookie:??$cookie\n";
15、$request.="\r\n";
16、fwrite($fp,$request);
17、while(!@feof($fp)){
18、$result.=@fgets($fp,1024);
19、}
20、fclose($fp);
21、return$result;
22、}
23、}
24、//獲取url的html部分,去掉header
25、functionGetUrlHTML($url,$cookie=false)
26、{
27、$rowdata=get_url($url,$cookie);
28、if($rowdata)
29、{
30、$body=stristr($rowdata,"\r\n\r\n");
31、$body=substr($body,4,strlen($body));
32、return$body;
33、}
34、?returnfalse;
35、}
36、?
參考資料:
php-file_get_contents
首先你要建立一個表,例如是注冊的用戶表user
,里面的結(jié)構(gòu)有字段
id,
name,nickname,email等。
然后在你的表單處form
action="a.php"
method="post"
name="regform"(如果有圖片上傳,還要加上enctype="multipart/form-data")
,那么點擊表單提交按紐后,此表單將會交給處理頁a.php來作處理。
如果簡單點,你就直接可以將表單傳遞過來的數(shù)據(jù)$_POST,直接用sql插入語句,insert
into來插入到數(shù)據(jù)庫,表user中。例如insert
into
user
set
name='".$_POST['name']."'.............................
$conn_ID = mysql_connect('localhost','root','password');
mysql_select_db("secretdata",$conn_ID);
//$sql="select*from whoareyou where username = '$username'";
$result = mysql_query("select*from whoareyou where username = '$username'");
$username = $_POST['username'];
$userpass = $_POST['userpass'];
$howlong = $_POST['howlong'];
if(mysql_fetch_array($result))
{
echo "center h3對不起! 此用戶名已經(jīng)被他人使用,請回到前頁重新輸入:/h3/centerbr";
exit;
}
以上是你代碼的原文,下面是改動后的樣子:
$conn_ID = mysql_connect('localhost','root','password');
mysql_select_db("secretdata",$conn_ID);
$username = $_POST['username']; //將這一行移動到需要使用$username之前,要知道,php是有先后執(zhí)行順序的。
//$sql="select*from whoareyou where username = '$username'";
$result = mysql_query("select*from whoareyou where username = '$username'"); // 也就是這里,在這條語句之前沒有對$username進行定義,那么它就永遠(yuǎn)是NULL!!!!!
$userpass = $_POST['userpass']; //
$howlong = $_POST['howlong']; //
if(mysql_fetch_array($result))
{
echo "center h3對不起! 此用戶名已經(jīng)被他人使用,請回到前頁重新輸入:/h3/centerbr";
exit;
}
在沒有if、for、while等改變程序執(zhí)行順序的語句出現(xiàn)時,php是按照語句的先后執(zhí)行順序依次執(zhí)行,下面舉個例子:
echo $a; //這里將不顯示任何東西。
$a=1;
echo $a; //這里將顯示數(shù)字1,而不是下方再次定義后的2?。?!
$a=2;
echo $a; //這里將顯示最后一次定義的數(shù)字2!!
另外,強烈建議將數(shù)據(jù)庫連接、查詢、修改等等一系列語句進行類的封裝,既安全,又省力。
分享標(biāo)題:注冊表單數(shù)據(jù)的收集php 表單收集信息
網(wǎng)頁地址:http://chinadenli.net/article40/hpeiho.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供靜態(tài)網(wǎng)站、網(wǎng)站改版、、品牌網(wǎng)站設(shè)計、云服務(wù)器、軟件開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)