/    Sign up×
Community /Pin to ProfileBookmark

file get contents does not work without html file extension

With [url]http://www.xxx.com/xxx/xxx/xxx.htm[/url] url
file_get_contents works.

[code=php]echo file_get_contents(‘http://www.xx.xx.com/xxx/xxx/xxx.htm’);[/code]

But with [url]https://www.xxx.com/xxx/xx/xxx/xxx[/url] url, it does not show anything(not working)

[code=php]echo file_get_contents(‘https://www.xxx.com/xxx/xx/xxx/xxx’);[/code]

Actually this happen with my old xammp.

But using wamp 2.0 this code below will also work

[code=php]echo file_get_contents(‘https://www.xxx.com/xxx/xx/xxx/xxx’);[/code]

So why does in my old xammp this code does not work?

[code=php]echo file_get_contents(‘https://www.xxx.com/xxx/xx/xxx/xxx’);[/code]

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogApr 01.2016 — I'm guessing the non-working URL is doing a redirect, which file_get_contents() won't follow by default, in which case you may need to try something like this: https://github.com/php-vcr/php-vcr/issues/138 (though I'm more inclined to use cURL for http requests, and leave file_get_contents() for actual file system stuff).
Copy linkTweet thisAlerts:
@anishgiriauthorApr 04.2016 — I'm guessing the non-working URL is doing a redirect, which file_get_contents() won't follow by default, in which case you may need to try something like this: https://github.com/php-vcr/php-vcr/issues/138 (though I'm more inclined to use cURL for http requests, and leave file_get_contents() for actual file system stuff).[/QUOTE]

In my old xampp, I tried this url that has .htm extension and it works.

$curl = curl_init('http://www.xxx.com/xxx/xxx/xxx.htm');

curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);

curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

$page = curl_exec($curl);

curl_close($curl);

print_r($page);[/QUOTE]


But if the url does not have extension, it won't work.
$curl = curl_init('http://www.xxx.com/xxx/xxx/xxx');[/QUOTE]

But on wamp 2.0, even(using curl) if the url does not have extension, it will still work.

Maybe the problem is the curl that my xampp uses? Does this php curl have different versions?
Copy linkTweet thisAlerts:
@anishgiriauthorApr 04.2016 — Looking a bit further, I realize that url with https are the one that is not working with my old xamp. This is a ssl cert issue

I tried adding [B]curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);[/B] But it still does not work.


[code=php]$curl = curl_init('https://www.xxxx.com/xxx/xxx');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$page = curl_exec($curl);
curl_close($curl);
print_r($page[/code]
×

Success!

Help @anishgiri 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.19,
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,
)...