Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    May 2011
    Posts
    303
    Thanks
    29
    Thanked 0 Times in 0 Posts

    $_SERVER["REDIRECT_STATUS"] to get all headers

    Just want to know how to get status headers:
    PHP Code:
    <?php
      $HttpStatus 
    $_SERVER["REDIRECT_STATUS"] ;
      
    statusFunc($HttpStatus);
    ?>
    This would work and can I place in my init.php + would it work for a 403?

  • #2
    Regular Coder
    Join Date
    Jul 2012
    Location
    London
    Posts
    473
    Thanks
    4
    Thanked 86 Times in 86 Posts
    Simple method (Works only with apache)

    apache_request_headers()

    Code:
    <?php
    $headers = apache_request_headers();
    
    foreach ($headers as $header => $value) {
        echo "$header: $value <br />\n";
    }
    ?>
    If you are not running PHP with apache, you could use:

    Code:
    <?php
    function parseRequestHeaders() {
        $headers = array();
        foreach($_SERVER as $key => $value) {
            if (substr($key, 0, 5) <> 'HTTP_') {
                continue;
            }
            $header = str_replace(' ', '-', ucwords(str_replace('_', ' ', strtolower(substr($key, 5)))));
            $headers[$header] = $value;
        }
        return $headers;
    }
    ?>
    Source: http://stackoverflow.com/questions/5...-header-in-php

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    You mean if you set up an error document handler for 404/403? Then yeah, if its forwarded you can find it under the REDIRECT_STATUS header.
    Of course it wouldn't work by itself. If you trigger a 404 or 403 accessing a script, that would indicate that it doesn't exist or that it cannot be accessed through security. If that triggers a 403 without a custom error handler, then it would just present the 404/403 browser error.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •