• 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

How can I easily switch between PHP versions on Mac OSX?

Load a .env file with PHP

Why getting "Build step 'Execute shell' marked build as failure" error while creating a backup tar for files

Filter WooCommerce related products by Polylang language

LARAVEL: How to fetch id dynamically in a query builder?

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'posts.post' doesn't exist

How to install ZeroMQ for PHP on an Alpine Linux container?

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

Check for PDO Results, If None Display Message, If Yes then Loop Through

yii2 and mssql insert varbinary into model

How do I loop through an MS SQL database with VB.NET?

Make survey at laravel 5.4 and MySQL

woocommerce get_order_report_data to show order_item_id

Docker & Laravel : configure: error: Package requirements (oniguruma) were not met

How to Generate PDF invoice to XML format using mPDF

About Contact Privacy policy Terms and conditions