• 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

Show rotation of tweets using current day of month

Warning: sqlite_query() expects parameter 1 to be resource, string given

Transform array, set each array element with parent key php

301 Redirect to remove query string on homepage only

PHP -> Next nearest date defined by array of days in week

Fatal error: Uncaught Error: Call to undefined method mysqli_stmt::fetch_assoc() [duplicate]

Facebook API, get page post link (PHP)

GuzzleHttp Hangs When Using Localhost

if statement inside concatenation

Yii2 redirecting to previous page after login

Laravel csrf token mismatch for ajax POST Request

How to fix " Uncaught TypeError: Argument 1 passed to JpGraphException::defaultHandler() " problem in php 7.1.3 and jpgraph 4.2.6?

Cant seem to get the Pagination to work on my WooCommerce REST API application?

How to reset Laravel AuthManager/guards in between API calls in tests?

shell errors running php exec

About Contact Privacy policy Terms and conditions