• 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

Warning file_get_contents () failed to open stream: HTTP request failed! HTTP/1.0 402 Payment Required

401 Unauthorized only occurring on some pages in Laravel 8

how to redirect the user back to desired URL after login page in PHP?

Log a user out of a website when they put their computer to sleep

Laravel UUID generation

The sum of the user's points

phpmyadmin : Depends: php-twig (>= 2.9) but 2.6.2-2 is to be installed. WHAT?

get attribute from class not working php 7

Laravel passport auth token not working after moving to different server

Nginx RTMP not recording

How to get the total hour from starting time to end time in php

Lumen - Postgresql setup - Composer

WooCommerce Subscriptions: Remove role on cancelled subscription

Unable to match results of php hash_hmac() and coldfusion hmac()

Not able to access model in the controller mautic

About Contact Privacy policy Terms and conditions