M
M
Millerish2015-12-04 15:04:40
PHP
Millerish, 2015-12-04 15:04:40

file_get_contents is not reading the page, why?

Good afternoon!
Tell me, why can not read some sites file_get_contents? www.example.com as in the example - reads, but www.baza-firm.com.pl - no.
Please tell me why and how to fix it.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
Evgeny Svirsky, 2015-12-04
@Millerish

I'm sure you should add a header to emulate a browser. Some kind of protection against spiders;)

<?php
$options = array(
  'http'=>array(
    'method'=>"GET",
    'header'=>"User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Firefox/38.0\r\n"
  )
);
$context = stream_context_create($opts);
file_get_contents('http://www.baza-firm.com.pl', false, $context)

R
romy4, 2015-12-04
@romy4

1. what does file_get_contents output via var_dump?
2. what's in the headers?

E
Eugene, 2015-12-04
@Nc_Soft

Use Guzzle

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question