Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Dennis J
February 10, 2010, 12:55 am
rate this thread
Hello, I am relatively new to all the coding.
But I have a question regarding cURL and PHP. How do I execute a cURL
command in PHP?
I've read a few hours on the net about cURL, but I am having a hard
brain freeze due to all the complex stuff.
curl -u user:password http://www.mysite.com
Dennis J wrote:
You can always use exec() to execute the command, but PHP has a whole
series of cURL functions and options which should do what you want.
Check them out first.
Remove the "x" from my email address
JDS Computer Training Corp.
February 10, 2010, 8:38 am
El 10/02/2010 1:55, Dennis J escribió/wrote:
In general, it's better the check the official manual first:
In "Function Reference-> Other Services" (yep, it's not very obvious)
you'll find there're builtin cURL functions in PHP, so you don't need to
use the command line tool:
Have a look at the example and elaborate on it.
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
Depending on the options you'll need, you can set the options as below
code (I required a security certificate on the host so my settings set
$url = "http://www.example.com ";
$credentials = "user:pass"; // using : to split un/pw
// Initialize session and set URL.
$ch = curl_init();
// set up the connection
curl_setopt($ch, CURLOPT_URL, $url);
// Set so curl_exec returns the result instead of outputting it.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// set the username and password
curl_setopt($ch, CURLOPT_USERPWD, $credentials);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_CAINFO, "/path/CertSigningAuthority.crt");
// Get the response and close the channel.
$reply = curl_exec($ch);
$info = curl_getinfo($ch);