/    Sign up×
Community /Pin to ProfileBookmark

CURL on WAMPSERVER

I’ve got a basic CURL question. Using WAMPSERVER I get nothing with this code

When I check PHP extensions and PHPINfo curl is ticked and enabled?

Is there something else I need to do?

“`
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, ‘https://www.google.co.nz’);
$response = curl_exec($curl);
echo $response;
“`

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogFeb 25.2022 — Also set the CURLOPT_RETURNTRANSFER option to true. (Otherwise you'll just get the returned HTTP headers.) And it's always good to check for errors:
[code=php]
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://www.google.co.nz');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
if($response === false) {
die("cURL failed: '".curl_error()."'");
}
echo "<pre>".htmlentities($response)."</pre>";
[/code]

However, testing that on my machine I get an empty string, so suspect that they check some http headers to try to weed out bots and such, so you may need to set additional options to provide things like user-agent headers and such. (I tried switching it to www.php.net and got a bunch of HTML back.)
Copy linkTweet thisAlerts:
@kiwisauthorFeb 25.2022 — @NogDog#1642863

You need to pass in $curl to the error handler, I get this

cURL failed: 'SSL certificate problem: unable to get local issuer certificate'
Copy linkTweet thisAlerts:
@NogDogFeb 26.2022 — Ugh...SSL stuff is _not_ my strong suit. You could try setting CURLOPT_SSL_VERIFYPEER to false. That's worked for me in the past, but not sure if it will work in this situation, or if you'd have to set up certs and stuff to make that connection. 🤷
×

Success!

Help @kiwis spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...