I have been getting an "500 Internal Server Error" whenever I use header().

Here's a snippet of my emails with my host:

[host support to me]
Re: 500 Internal Server Error

Make sure that you are not using any .htaccess PHP directives and
that any files associated with your PHP scripts do not have group or

world write permissions.

[me to support]
OK. I figured out what the problem is:

Note: no .htaccess PHP directives here folks...

Anytime I try to use a header() function, I get the error. When I take it out, no error. It is REALLY necessary to be able to write
headers....redirection, authentication, and the list goes on. Two violators below....

  1. if($group <= 2) {
    header("Location:http://www.foo.com/admin.php");
    } else { etc......
  2. if (!isset($PHP_AUTH_USER)) {
    //IF EMPTY SEND HEADER TO BRING UP DIALOG BOX
    header("WWW-Authenticate: Basic Realm=\"foo\",stale=FALSE");
    header("HTTP/1.0 401 Unauthorized");
    echo "You are not authorized to enter this section of the
    site!\n";
    exit;
    } else { etc....

Both pretty basic - and necessary

[host to me]
Are you suggesting that we need to recompile PHP to get this working or is this something that can be fixed by modifying the master
php.ini files? Please advise.
END>>>>>>>>>>>>>>>>>>>>>>

I don't know enough about PHP.ini to answer them, and they don't seem to either!
Any Suggestions?

    I think you need to find out if it's the header() function itself that's causing the error, or the sending of the headers. Try header('foo'); or something and see if you still get a 500.

      This works:

      header("Location: http://www.foo.com");

      This gets the 500 error:

      header('WWW-Authenticate: Basic Realm="foobarina"');
      header('HTTP/1.0 401 Unauthorized');
      echo("Authorization Required.");
      exit;

        Try Apache/IIS module PHP, not cgi mode.

          Write a Reply...