Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //set POST variables
- $url = 'http://domain.com/get-post.php';
- $fields = array(
- 'lname' => ($last_name),
- 'fname' => ($first_name),
- 'title' => ($title),
- 'company' => ($institution),
- 'age' => ($age),
- 'email' => ($email),
- 'phone' => ($phone),
- // Upload a file, by prepend @ followed by file full path
- 'photo' => sprintf('@%s', '/home/abc/pic/cat.jpg')
- );
- //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);
- curl_setopt($ch, CURLOPT_HEADER, 1);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- //execute post
- $strContents = curl_exec($ch);
- // Get the header and body
- $intHeaderSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
- $strHeader = substr($strContents, 0, $intHeaderSize);
- $strBody = substr($strContents, $intHeaderSize);
- // handle error; error output
- if(curl_getinfo($ch, CURLINFO_HTTP_CODE) !== 200) {
- var_dump($strBody);
- }
- //close connection
- curl_close($ch);
- /*
- $strHeader can be exploded for further use
- $arrHeader = explode("\r\n", $strHeader);
- */
- /*
- curl_getinfo($ch) returns an array similar to the following:
- Array
- (
- [url] => http://www.example.com/path/to/form
- [content_type] => text/html; charset=UTF-8
- [http_code] => 200
- [header_size] => 516
- [request_size] => 197
- [filetime] => -1
- [ssl_verify_result] => 0
- [redirect_count] => 0
- [total_time] => 2.256708
- [namelookup_time] => 0.672754
- [connect_time] => 0.899986
- [pretransfer_time] => 0.900012
- [size_upload] => 240
- [size_download] => 18717
- [speed_download] => 8293
- [speed_upload] => 106
- [download_content_length] => 0
- [upload_content_length] => 240
- [starttransfer_time] => 1.12957
- [redirect_time] => 0
- )
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement