PHP's curl implements get and post. read PHP's curl implements get and post. similar to host service providers such as dreamhost, it shows the use of fopen. Php curl supports FTP, FTPS, HTTPHTPPSSCPSFTPTFTPTELNETDICTFILE, and LDAP. Curl supports SSL certificates and HT
Similar to host service providers such as dreamhost, it shows the use of fopen. Php curl supports FTP, FTPS, http htpps scp sftp tftp telnet dict file and LDAP. Curl supports SSL certificates, http post, http put, and FTP uploads, kerberos, HTT-based Upload, proxy, cookie, user + password proof, file transfer recovery, and http proxy channel are the most common methods based on http get and post.
Code implementation:
1. http get implementation
$ Ch = curl_init ("http://www.devdao.com /");
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, true );
Curl_setopt ($ ch, CURLOPT_BINARYTRANSFER, true );
$ Output = curl_exec ($ ch );
$ Fh = fopen ("out.html", 'w ');
Fwrite ($ fh, $ output );
Fclose ($ fh );
2. http post implementation
// Extract data from the post
Extract ($ _ POST );
// Set POST variables
$ Url = 'http: // www.webjx.com/get-post.php ';
$ Fields = array (
'Lname' => urlencode ($ last_name ),
'Fname' => urlencode ($ first_name ),
'Title' => urlencode ($ title ),
'Company' => urlencode ($ institution ),
'Age' => urlencode ($ age ),
'Email '=> urlencode ($ email ),
'Phone' => urlencode ($ phone)
);
// Url-ify the data for the POST
Foreach ($ fields as $ key => $ value) {$ fields_string. = $ key. '='. $ value .'&';}
Rtrim ($ fields_string ,'&');
// Open connection
$ Ch = curl_init ();
// Set the url, number of POST vars, POST data
Curl_setopt ($ ch, CURLOPT_URL, $ url );
Curl_setopt ($ ch, CURLOPT_POST, count ($ fields ));
Curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ fields_string );
// Execute post
$ Result = curl_exec ($ ch );
// Close connection
Curl_close ($ ch );