开发者

Header not working PHP

开发者 https://www.devze.com 2023-03-23 06:03 出处:网络
I am using MAMP, NetBeans to develop php website on my Mac. I wrote the following code but ran into error repeatedly. I tried all the commented lines but neither one works.

I am using MAMP, NetBeans to develop php website on my Mac. I wrote the following code but ran into error repeatedly. I tried all the commented lines but neither one works.

<?php
if ($output == 1) //Authenticated = yes
{

    $url = "http://www.google.com”;
    //error_reporting(E_ALL); ini_set('display_errors', 'On'); 
    //
    //  include('./dlheader.inc');

    //header("Cont开发者_如何学运维ent - Length: 0");
    // header("Location: http://google.com", true, 303);
    // header("Location:".$url);
    //  header("Location: http://google.com", true);
    //   exit;

    /*          flush();
          if (headers_sent()) {
die('cannot send location header (anymore)');
}
    else {
    header('Location: '.$url);
    die();
}

*/
    //echo '<html><head><meta http-equiv="refresh" content="1;url=' . $url . '"/>;

}
?>

This code is exactly after the <body> tag. Thanks for your help in advance.


If this is exactly your code, you need to fix this curly quote. It looks like it was copy/pasted from a website or word processor.

$url = "http://www.google.com”;
                            ^^^^

Should be

$url = "http://www.google.com";

Since it is not a proper double-quote, PHP does not see the string as being closed and all subsequent code is treated as part of the string until another " is encountered.


If that space before the php tag is in your file then header() won't work. No white space or any sort of output can occur in a php file before the header(), or it won't work as headers will have already been sent.

You can check this with the boolean result from the function headers_sent():

if(headers_sent())
{
    echo "headers already sent!";
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号