Questions tagged [get-headers]
90 questions
15
votes
4 answers
How to set timeout for get_meta_tags() & get_headers()
I've been using the get_meta_tags() & get_headers() PHP functions, and need to set a timeout value in case the website is slow or unresponsive. Does anyone know how to do it?

rob
- 307
- 2
- 5
- 9
11
votes
1 answer
PHP - Errors with get_headers and SSL
This is my code
$url = 'http://www.wikipedia.com'; // URL WITH HTTP
$hurl = str_replace("http", "https", $url); // URL WITH HTTPS
$urlheads = get_headers($url, 1);
$surlheads = get_headers($hurl, 1);
$urlx = false;
$surlx = false;
foreach…

codexy
- 413
- 1
- 5
- 18
9
votes
2 answers
Something faster than get_headers()
I'm trying to make a PHP script that will check the HTTP status of a website as fast as possible.
I'm currently using get_headers() and running it in a loop of 200 random urls from mysql database.
To check all 200 - it takes an average of 2m 48s.
Is…

Clarkey
- 698
- 3
- 11
- 28
8
votes
3 answers
how to set user agent for get_headers PHP function
I know It's easy to set user agent for curl but my code is based on get_headers, by default get_headers user agent is empty.
thanks for any help.

Farhad
- 803
- 4
- 8
- 20
8
votes
2 answers
How to use request.getHeader("Referer")
In my current project, I have a shopping cart integrated with the main site. Now I have to create some mini sites to display the data retrieved from main site. When the user click buy now button in mini site, it should redirect to the main shopping…

Mujahid
- 1,227
- 5
- 32
- 62
8
votes
1 answer
PHP - `get_headers` returns "400 Bad Request" and "403 Forbidden" for valid URLs?
Working solution at bottom of description!
I am running PHP 5.4, and trying to get the headers of a list of URLs.
For the most part, everything is working fine, but there are three URLs that are causing issues (and likely more, with more extensive…

Birrel
- 4,754
- 6
- 38
- 74
5
votes
1 answer
Using get_headers with a proxy
In order to check if an URL is an image, I use the PHP function get_headers. In normal conditions, it works very well.
But when I'm behind a proxy, it causes a timeout exception. I had the same problem with file_put_contents but I solved it by…

Arnaud
- 4,884
- 17
- 54
- 85
4
votes
2 answers
Why get_headers() returns 400 Bad request, while CLI curl returns 200 OK?
Here's the URL: https://www.grammarly.com
I'm trying to fetch HTTP headers by using the native get_headers() function:
$headers = get_headers('https://www.grammarly.com')
The result is
HTTP/1.1 400 Bad Request
Date: Fri, 27 Apr 2018 12:32:34…

Limon Monte
- 52,539
- 45
- 182
- 213
4
votes
2 answers
Get the right http status code php
My code give me http status code 302 when I visit google but when I visiting with firefox browser and checking the status with firebug, there the status is 200.
Here is my code:
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0…

biox
- 1,526
- 5
- 17
- 28
3
votes
1 answer
php get_headers location
how to use php get_headers only get location part?
var_dump(get_headers('http://www.google.com',1));
This return:
array(12) { [0]=> string(18) "HTTP/1.0 302 Found" ["Location"]=> string(21) "http://www.google.it/" ... }
Then I use
echo…

fish man
- 2,666
- 21
- 54
- 94
3
votes
3 answers
Exception handling with get_meta_tags() & get_headers()?
In PHP, I am using get_meta_tags() and get_headers(), however, when there is a 404, those two functions throw a warning. Is there any way for me to catch it?
Thanks!

rob
- 307
- 2
- 5
- 9
3
votes
0 answers
PHP - Differences between `get_headers` and `stream_get_meta_data`?
Intro / Disclaimer
Decent chunks of this are outputs that can largely be ignored. It is still a bit of a reader, but I'm trying to be thorough in my analysis and questioning. If you are familiar with stream_get_meta_data, you would be fine to skip…

Birrel
- 4,754
- 6
- 38
- 74
3
votes
1 answer
Warning: get_headers() This function may only be used against URLs in
I want to check if an external url exists and I've tried using different functions. Most functions use get_headers() function and this always shows me the warning "Warning: get_headers () [function.get-headers]: This function May only be used…

PoseLab
- 1,841
- 1
- 16
- 22
2
votes
1 answer
get_headers add skip when external server not responding
I use the following code to check the file size of a external pdf.
But I want to add a timeout and skip if the external server does not respond within 1 second. How can I achieve this?
My current code:

JGeer
- 1,768
- 1
- 31
- 75
2
votes
1 answer
How is get_header() calling a specific PHP file?
I'm trying to learn Wordpress Structure with investigating some free plugins/themes.
I'm working on "Renger Blog Theme" right now, but I couldn't understand something. I've checked get_header() page in the WP manual but it still looks like a magic…

Akin A
- 33
- 1
- 1
- 5