本文目錄一覽:
- 1、PHP怎麼獲取表單提交的數據啊?
- 2、php怎麼獲取表單中提交的數據?
- 3、PHP獲取表單的值
- 4、怎麼利用php腳本獲取表單控件的值
- 5、php怎麼從表單接收數據
- 6、php 如何獲取表單中的一系列值?
PHP怎麼獲取表單提交的數據啊?
一、用file_get_contents以get方式獲取內容,需要輸入內容為:
1、?php
2、$url=”;
3、$html = file_get_contents($url);
4、echo $html;
5、?
二、用file_get_contents函數,以post方式獲取url,需要輸入內容為
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方式獲取內容,需要輸入內容為
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 “url header: {$header} br”:
8、echo “url body: $result”;
9、fclose($fp);
10、?
四、用fopen打開url,以post方式獲取內容,需要輸入內容為
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函數打開url,以get方式獲取完整的數據,包括header和body,需要輸入內容為
1、?php
2、function get_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、return false;
10、} else {
11、$request = “GET $query HTTP/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、function GetUrlHTML($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、 return false;
35、}
36、?
參考資料:
php-file_get_contents
php怎麼獲取表單中提交的數據?
在獲取表單數據中,最常用的自動全局變量是$_GET和$_POST,它們分別獲取通過GET方法提交的數據和通過POST方法提交的數據。
比如一個名稱為”user”的文本框表單控件,如果用GET方法提交,可以用 $_GET[“user”]或者$_GET[‘user’]
獲取它提交的值。
PHP獲取表單的值
1.
form id=”form1″ name=”form1″ method=”get” action=”resetpassword.php”
改成
form id=”form1″ name=”form1″ method=”post” action=”resetpassword.php”
2.
$oldpw = $_GET[‘oldpw’]; //獲取舊密碼
$newpw = $_GET[‘newpw’]; //獲取第1次輸入的新密碼
$newpw2 = $_GET[‘newpw2’]; //獲取第2次輸入的新密碼
改成
$oldpw = $_POST[‘oldpw’]; //獲取舊密碼
$newpw = $_POST[‘newpw’]; //獲取第1次輸入的新密碼
$newpw2 = $_POST[‘newpw2’]; //獲取第2次輸入的新密碼
怎麼利用php腳本獲取表單控件的值
看一下$_POST[“submit”]是把表單內容提交到服務器里,$_GET[“submit”]把表單內容提交到網頁中。你看看手冊就OK!
php怎麼從表單接收數據
PHP 可以通過POST、GET方法獲取到表單提交的數據
獲取到的POST、GET是數組形式的值,需要通過鍵值來詳細獲取相應的值
比如: index.php 頁面
下面是POST方法
form name=”form1″ method=”post” action=”index.php”
input type=”text” name=”contents” value=””
input type=”submit” value=”提交”
/form
?php
//獲取表單提交的數據
$contents = $_POST[‘contents’];
echo $contents;
?
也可以是下面是GET方法
form name=”form1″ method=”get” action=”index.php”
input type=”text” name=”contents” value=””
input type=”submit” value=”提交”
/form
?php
//獲取表單提交的數據
$contents = $_GET[‘contents’];
echo $contents;
?
POST相對於GET方法,更好一些,可以提交大量數據,以及更安全些。
php 如何獲取表單中的一系列值?
php是服務器端腳本,如果上面的表單是你服務器端編寫的,可以直接傳值 id、class 等給php腳本進行查詢就可以了;如果上面的表單是你獲取其他站點上,那通常的做法,可以使用正則來提取值再傳給php腳本進行查詢。
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/285541.html