• Categories
    • PHP
    • phpMyAdmin
    • PHPMailer
    • FFMpeg
    • PHPEXcel
    • PHPDoc
    • PHPUnit
    • CakePHP
    • CakePHP 2.0
    • Cake PHP 2.1
    • CakePHP Model
    • Facebook PHP SDK
    • composer-php
    • PHP 7
    • PHP GD
    All Categories
  • About

file_get_contents() without "Http" to access external URL [closed]

php


PHP Snippet 1:

<?php

$ctx = stream_context_create(array(
    'http' => array(
        'timeout' => 16.0 // seconds
    )
));

$contents = file_get_contents('http://...', FALSE, $ctx);

// do something with $contents

PHP Snippet 2:

$ ./test
{
  "headers": {
    "Host": "httpbin.org"
  }
}

$ cat test
#!/usr/bin/env php
<?php

die(file_get_contents('http://httpbin.org/headers'));

Related Snippets

Laravel s3 upload file with metadata using pre-signed url

Change user role if checkout custom checkbox is checked in WooCommerce

cakephp save drag and drop list order to database

Unable to guess the mime type as no guessers are available Laravel 5.2

PHP: set a (deep) array key from an array [closed]

Where do I need to place a hook for phpunit?

PHP DOTENV unable to load env vars

How to get values inside <![CDATA[values]] > using php DOM?

php - add comma thousands separator but remove trailing zeros

how to identify the web server name of remote host

Smarty: undefined extension class 'Smarty_Internal_Method_Get_Template_Vars'

PHP each() function replacement

Laravel Mix Uncaught ReferenceError: $ is not defined

Xdebug 3 not showing in phpinfo on m1 Monterey

shell errors running php exec

About Contact Privacy policy Terms and conditions