views:

497

answers:

1

Hi, I I keep getting a 500 Internal Server Error when the script below reaches the header('location:php_email_thankyou.php'). Im not sure what is causing this, as I can place the header expression before or after the if statements and it works fine. In firebug it mentions a GET request for the php_email_thankyou.php page not sure if that means anything...

<?php

ini_set('display_errors', 'On');   
error_reporting(E_ALL | E_STRICT);    

include('php/cl/cl_val.php');  
$val = new Validate;  
$print_errors = false;  

if (isset($_POST['email(email)'])){  
    if(isset($_SERVER['HTTP_X_REQUESTED_WITH']))  
    {  
        $validation = $val->clean($_POST);  
        if (isset($validation['send']))   
        {  
            header('location:php_email_thankyou.php');  
            exit();  
        }  
        else   
        {  
            print json_encode($validation);  
            exit();  
        }  
    }   
    else   
    {  
        $validation = $val->clean($_POST);  
    }  
}  

?>  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;  
<html xmlns="http://www.w3.org/1999/xhtml"&gt;  

Thanks heaps!

A: 

HTTP/1.1 requires the location used to be an abolute path, not relative. Try this;

header('Location: http://yourdomain.com/php_email_thankyou.php');  
MatW
That's now how you think, you can specify the relative path too.
Sarfraz
Browsers tend to support relative redirects, but the RFC clearly requires an absolute URI, as MatW stated: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.30 So don't be surprised if relative paths in the Location header fail to work with certain user agents. "It works in firefox" doesn't mean it's right.
Frank Farmer
Hey thanks everyone for your answers. The target file is O.K, I can navigate to it fine.I dont think it is an absolute/relative issue, as when I place the header redirect in the first line or even just before the DOCTYPE declaration it works fine as is, so I appreciate it may not be the technically correct syntax, but it still works.I was thinking maybe its an ajax issue? Perhaps the page is still loading will the ajax is ticking over.
Globalz
@globa: check the server's error log. There'll be more details on WHAT caused the 500 there. The 500 output you see in the browser is deliberately minimalized and is utterly useless for any form of debugging.
Marc B