首先我们在页面使用开启 curl,并向某个页面post数据。
代码如下:
折叠展开PHP 代码
- <?php
- $uri = "http://www.a.com/test.php";//这里换成你服务器的地址
-
- $data = array (
- 'name' => 'tanteng'
-
- );
-
- $ch = curl_init ();
-
- curl_setopt ( $ch, CURLOPT_URL, $uri );
- curl_setopt ( $ch, CURLOPT_POST, 1 );
- curl_setopt ( $ch, CURLOPT_HEADER, 0 );
- curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
- curl_setopt ( $ch, CURLOPT_POSTFIELDS, $data );
- $return = curl_exec ( $ch );
- curl_close ( $ch );
-
- print_r($return);
接收数据的页面代码:
折叠展开PHP 代码
- <?php
- if(isset($_POST['name'])){
- if(!emptyempty($_POST['name'])){
- echo '您好,',$_POST['name'].'!';
- }
- }