0

I am writing a script that uses curl to grab data from my web server.

Unfortunately, thats only a one-way communication. What I would like to do is send a php file some info through curl, then grab the info that php returns. But I am not sure how to do this with curl.

Basicly:

CURL: Hey php file. In the mysql database, what is Roberts age?
PHP: Hang on here a moment....23
CURL: Got it, thanks :)

I know how to do all the server side stuff (like php receiving the info and looking up mysql stuff) but have no idea how Curl is suppose to grab php's return info once it is processed.

Any tutorials/ideas? Thanks a bunch!! :)

Edited by mybluehair: n/a

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by fornandakishore
0

Yes, You can get the result from CURL....

Below is the example to get weather information from google

// initializing connection
$curl = curl_init();

// saves us before putting directly results of request
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);

// url to get
curl_setopt($curl, CURLOPT_URL, 'http://www.google.com/ig/api?weather=sydney&h1=english');

// timeout in seconds
curl_setopt($curl, CURLOPT_TIMEOUT, 20);

// useragent
//curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER);

// reading content
$content = curl_exec($curl);

// closing connection
curl_close($curl);

in the $content variable you can able to get all the data...

Hope this can help you ... :)

0

Okay. Thanks for the example. How would I implement this with php? I'd like to send a php file some _POST data and have it be able to receive whatever the php file spits back out.

For example, kind of like if a user is on a webpage and types his age into a form then clicks submit. He would be directed to the next php file that would grab the form data in a _POST request. Then the php would add it to the mysql database and print out confirmation to the user. I'd like to do this same thing (I know how to do all the php stuff) but with curl. I need to know how to send data to a php file, then receive any data that php comes back with.

Any ideas?

Edited by mybluehair: n/a

0

Okay. Thanks for the example. How would I implement this with php? I'd like to send a php file some _POST data and have it be able to receive whatever the php file spits back out.

For example, kind of like if a user is on a webpage and types his age into a form then clicks submit. He would be directed to the next php file that would grab the form data in a _POST request. Then the php would add it to the mysql database and print out confirmation to the user. I'd like to do this same thing (I know how to do all the php stuff) but with curl. I need to know how to send data to a php file, then receive any data that php comes back with.

Any ideas?

Okay, To send POST values you need to use this line...

// url to get
curl_setopt($curl, CURLOPT_URL, 'URL to the site');

// timeout in seconds
curl_setopt($curl, CURLOPT_TIMEOUT, 20);

curl_setopt($tuCurl, CURLOPT_POST, 1);

// useragent
//curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER);

// reading content
$content = curl_exec($curl);

// closing connection
curl_close($curl);

$content will return the result for that POST data that php comes back with.

For more information visit this link http://in.php.net/manual/en/book.curl.php

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.