I
I
Ibishka2020-05-06 18:08:05
PHP
Ibishka, 2020-05-06 18:08:05

How to find PHP HTTP response code?

In .htaccess

#401 Авторизация не выполнена
ErrorDocument 401 /error.php
#403 Access is denied
ErrorDocument 403 /error.php
#404 Page not found
ErrorDocument 404 /error.php
#500 Внутренняя ошибка сервера
ErrorDocument 500 /error.php

Ie I want to make one page for all errors and display the number of the error code how to get on the error page?
Found this one on the internet
error_reporting(E_ERROR | E_PARSE); 

// Initialize a variable into domain name 
$domain1 = 'https://contribute.geeksforgeeks.org'; 
  
// Function to get HTTP response code  
function get_http_response_code($domain1) { 
    $headers = get_headers($domain1); 
    return substr($headers[0], 9, 3); 
} 
  
// Function call  
$get_http_response_code = get_http_response_code($domain1); 
  
// Display the HTTP response code 
echo $get_http_response_code; 
?>

Is there a short version?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladislav Dvoryaninov, 2020-05-06
@Vlad16

https://www.php.net/manual/ru/function.http-respon...

W
wisgest, 2020-05-10
@wisgest

$_SERVER['REDIRECT_STATUS']under Apache, at least.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question