PhpDig.net

What is PhpDig?
PhpDig is a PHP MySQL based
Web Spider & Search Engine.




curl_exec

Name

curl_exec — Executes the operations that have been set up for the cURL session.

Synopsis

mixed curl_exec(curld);
int curld: Handle of the cURL session

Returns

FALSE on error; TRUE on success (but see below)

Description

After a cURL session has been created with curl_init() and any necessary options have been set with curl_setopt() , this function causes the session to execute the transfer and any other associated actions.

By default, curl_exec() returns TRUE on success and FALSE on error. Any returned data is then typically written to the appropriate file pointer: STDOUT by default, or something else if set (for instance, with CURLOPT_FILE). However, if the CURLOPT_RETURNTRANSFER option has been set to TRUE with curl_setopt() , any data retrieved by the transfer operation will not be output to a file pointer; rather, it will be returned by curl_exec() and may be assigned to a variable for later use.

Example

Example 190. Post to a web page and get the results

<?php
error_reporting(E_ALL);

/* POST some data to a Web page. curl_receive_vars.html can
 * be something like this:
 * <?php 
 * if (isset($HTTP_POST_VARS)) {
 *    echo "<pre>";
 *    echo "Current \$HTTP_POST_VARS:\n";
 *    print_r($HTTP_POST_VARS);
 *    echo "</pre>";
 * } 
 * ?>
 */
$url = 'http://www.foo.bar/curl_receive_vars.html';
$postfields = array ('username' => 'Myname',
                     'emailaddress' => 'myaddress@foo.bar');

if (!$curld = curl_init()) {
    echo "Could not initialize cURL session.\n";
    exit;
}

/* Prepare for the POST operation. */
curl_setopt($curld, CURLOPT_POST, true);

/* Give cURL the variable names & values to POST. */
curl_setopt($curld, CURLOPT_POSTFIELDS, $postfields);

/* The URL to which to POST the data. */
curl_setopt($curld, CURLOPT_URL, $url);

/* Indicate that we want the output returned into a variable. */
curl_setopt($curld, CURLOPT_RETURNTRANSFER, true);

/* Do it. */
$output = curl_exec($curld);

echo "Received data: <hr>$output<hr>\n";

/* Clean up. */
curl_close($curld);
?>



PHP Functions Essential Reference. Copyright © 2002 by New Riders Publishing (Authors: Zak Greant, Graeme Merrall, Torben Wilson, Brett Michlitsch). This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at http://www.opencontent.org/openpub/). The authors of this book have elected not to choose any options under the OPL. This online book was obtained from http://www.fooassociates.com/phpfer/ and is designed to provide information about the PHP programming language, focusing on PHP version 4.0.4 for the most part. The information is provided on an as-is basis, and no warranty or fitness is implied. All persons and entities shall have neither liability nor responsibility to any person or entity with respect to any loss or damage arising from the information contained in this book.

Powered by: vBulletin Version 3.0.7
Copyright ©2000 - 2005, Jelsoft Enterprises Ltd.
Copyright © 2001 - 2005, ThinkDing LLC. All Rights Reserved.