Jump to content

[SOLVED] Using Curl to retrieve some info


CMNetworx

Recommended Posts

I am on a host that does not allow fopen Unlike my last host.. So I am trying to recreate the same result with curl, but I don't know how to pass get variables to the url..

 

Can anyone help?

 

I know how to do this with post, but I need to be able to pass info using the Get method

 

$curl_handle=curl_init();

curl_setopt($curl_handle,CURLOPT_URL,'http://examplewebsite.com/info.php?info=$info');

curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);

curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);

$buffer = curl_exec($curl_handle);

curl_close($curl_handle);

 

Of course this doesn't work correctly because it asks the website for $info and not the actual variable..

 

 

With post It seems to pass fine

$curl_handle=curl_init();

curl_setopt($curl_handle,CURLOPT_URL,'http://website.com/info.php?info=$info);

curl_setopt($curl_handle,CURLOPT_POST,1);

curl_setopt($curl_handle,CURLOPT_POSTFIELDS, 'info=$info');

curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);

curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);

$buffer = curl_exec($curl_handle);

curl_close($curl_handle);

Link to comment
https://forums.phpfreaks.com/topic/37842-solved-using-curl-to-retrieve-some-info/
Share on other sites

Maybe try:

 

<?php

$info = "variable";
$url = "http://examplewebsite.com/info.php?info=".$info."";

$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,$url);
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.