note 128784 added to function.file-get-contents
| From: | brentcontact at daha dot us | Date: | Tue, 08 Aug 2023 10:55:43 +0000 |
| Subject: | note 128784 added to function.file-get-contents | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-220745@lists.php.net to get a copy of this message | ||
To prevent mixed content most browsers/functions will use the protocol already used if you specify
only // instead of http:// or https://. This is not the
case with file_get_contents. You must specify the protocol.
This does not work:
<?php
$jsonData = file_get_contents('//example.com/file.json');
print $jsonData;
?>
Specifying only 'example.com/file.json' without the double slash does not work either.
When running on Apache 2.4 , using $_SERVER['REQUEST_SCHEME'] is a better way to be
protocol agnostic.
<?php
$jsonData =
file_get_contents($_SERVER['REQUEST_SCHEME'].'://example.com/file.json');
print $jsonData;
?>
If using another web server, you may have to get the protocol another way or hard code it.
----
Server IP: 45.112.84.4
Probable Submitter: 45.91.157.134 (proxied: 97.125.18.92)
----
Manual Page -- https://php.net/manual/en/function.file-get-contents.php
Edit -- https://main.php.net/note/edit/128784
Del: integrated -- https://main.php.net/note/delete/128784/integrated
Del: useless -- https://main.php.net/note/delete/128784/useless
Del: bad code -- https://main.php.net/note/delete/128784/bad+code
Del: spam -- https://main.php.net/note/delete/128784/spam
Del: non-english -- https://main.php.net/note/delete/128784/non-english
Del: in docs -- https://main.php.net/note/delete/128784/in+docs
Del: other reasons-- https://main.php.net/note/delete/128784
Reject -- https://main.php.net/note/reject/128784
Search -- https://main.php.net/manage/user-notes.php