首页
开发手册
应用中心
工具
用户中心
Ease Template Curl Various usage tutorials
English
中文简体
English
上一篇
下一篇
CURL It provides a very convenient way to use for network interaction, each function has a small difference, remember not everyone is here to find the fault, please understand carefully. We set $url as a local development project ```php $url = 'http://localhsot/Foundphp'; ```
#### 1. tttp GET Retrieve Data Support web pages, photos, files, etc.。 ```php echo $tpl->curl($url.'/curl_result.php?t=get'); ```
#### 2. https GET Retrieve Data: The Hypertext Transfer Security Protocol supports web pages, photos, files, etc. We download Baidu photos, save them locally and display them. ```php $img = $tpl->curl('https://foundphp.com/plugin/view/default/images/logo_found.png'); $tpl->writer('baidu.png',$img); echo '
'; ``` display effect: ![](https://foundphp.com/plugin/view/default/images/logo_found.png)
#### 3. https Certificate Access: Some websites require authentication certificate to visit. ```php $tpl->curl_pem = 'cacert.pem'; //certificate file echo $tpl->curl('https://www.baidu.com/'); //Set the https website that needs to be visited ```
#### 4. POST: No-refresh submission data supports multi-dimensional arrays. ```php $post_data = array( 'name'=>'tonsen', 'info'=>array('gender'=>1,'height'=>178) ); echo $tpl->curl($url.'/curl_result.php?t=post',$post_data); ```
#### 5. Cookie: Pass cookies to the website to enable user login. ```php $post_data = array( 'name'=>'tonsen', 'id' =>1983 ); echo $tpl->curl($url.'/curl_result.php'); ```
#### 6. Custom Browser: The logo of the simulated browser can also be added to define your own logo. ```php $tpl->curl_agent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) FoundPHP/2.x'; echo $tpl->curl($url.'/curl_result.php'); ```
#### 6. Custom header information: Some websites use custom headers for login or verification, and the header identifiers are all capitalized. We submit US and PWD, and receive data through _SERVER on the server. ```php $tpl->curl_header = array( 'US: tonsen', 'PWD: 1231123' ); $post_data = array( 'usernamne'=>'tonsen' ); echo $tpl->curl($url.'/curl_result.php',$post_data); ``` result: $_SERVER['HTTP_US']与 $_SERVER['HTTP_PWD']the result is ```php http receive: tonsen 123123 post receive: tonsen ```
#### 7. Send Json Data: Just add a parameter of 1 after post_data to identify the JSON data. ```php $post_data = array( 'usernamne'=>'tonsen' ); echo $tpl->curl($url.'/curl_result.php',$post_data, 1 ); ```
#### 8. HTTP_RAW_POST_DATA: Simulate HTTP_RAW_POST_DATA to submit xml to the server to verify the data. The post_data here will automatically adapt as long as the string is used, and the array will be judged as post. ```php $post_data = 'FoundPHP is Good!'; echo $tpl->curl($url.'/curl_result.php',$post_data); ```
#### 9. Jump Adaptive: There is a jump to the visited page. The system automatically determines whether to continue to visit the jumped page. We visit the area where t is go, and instantly jump to the area where t is 301 and display the output content. ```php echo $tpl->curl($url.'/curl_result.php?t=go'); ```
#### 10. Upload a Single File: It is recommended to set set_time_limit(90) for uploading a single file without refreshing. If the file is too large, please use a longer time or other solutions. The post_data array only supports one-dimensional arrays. ```php $tpl->curl_file = array( 'name'=>'attach', 'file'=>'baidu.png' ); $post_data = array( 'name'=>'tonsen', 'group'=>'FoundPHP' ); echo $tpl->curl($url.'/curl_result.php?t=file',$post_data); ```