/    Sign up×
Community /Pin to ProfileBookmark

CURL_GETINFO returns empty results

Hello
I’m trying to get website results and check if it is down or up
I have this code it works fine and shows the result when enter google.com but with facebook.com it shows nothing

“`
if(!isset($_GET[‘url’]))
die(“enter url”);
$ch = curl_init($_GET[‘url’]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
if(curl_exec($ch))
{
$info = curl_getinfo($ch);
// echo ‘Took ‘ . $info[‘total_time’] . ‘ seconds to transfer a request to ‘ . $info[‘url’];
echo “<pre>” ;
print_r($info);
echo “<pre>”;

}

curl_close($ch);
“`

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@tracknutAug 14.2022 — if(curl_exec($ch))[/quote]
Be careful here, curl_exec() returns false on failure, but even on success the return value can be "falsy". Better to check the actual return, like:
if(curl_exec($ch) !== false)[/quote]
Copy linkTweet thisAlerts:
@SempervivumAug 14.2022 — @slake8#1645934

Please use code tags when posting code: `your code here` or triple backticks. I edited your posting accordingly.
×

Success!

Help @slake8 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 3.29,
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: @darkwebsites540,
tipped: article
amount: 10 SATS,

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

tipper: Anonymous,
tipped: article
amount: 10 SATS,
)...