php获取用户提交数据,php获取网页数据

php怎么获取form表单提交的数据

一般是用post获取提交的数据,如下实例:

创新互联服务项目包括尚义网站建设、尚义网站制作、尚义网页制作以及尚义网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,尚义网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到尚义省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!

form name="form1" method="post"

p用户名:input type="text" name="uname" //p

p密码:input type="password" name="upwd" //p

pinput type="submit" name="btn" value="提交" //p

?php

if ($_POST["btn"]){

echo '用户名:'.$_POST["uname"].'br';//三体教程

echo '密码:'.$_POST["upwd"];

}

?

/form

PHP 获取网页中用户输入的数据的函数

用户在表格form

中填写数据,然后提交到一个php文件,PHP文件使用函数获取数据

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

Name: input type="text" name="name"br

E-mail: input type="text" name="email"br

input type="submit" value="提交"

/form用户填写完username后提交到welcome.php文件,在welcome.php文件中,

html

body

Welcome ?php echo $_POST["name"]; ?br

Your email address is: ?php echo $_POST["email"]; ?

/body

/html$_POST["name"]就是用户输入的名字

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获取用户提交数据,php获取网页数据
本文来源:http://pwwzsj.com/article/heghso.html