mysterious php header relocation
Recently I have encountered non-working header redirect issue<?php
//some process code here
//........
header("Location: [url]http://www.mysite.com[/url]");
exit;
this code above is not working and there is no error been caught. It took me whole alot time for debugging the root of problem,
and still no luck in finding.
After went through the php.net, I found out this very useful function for debugging such issue
headers_sent();
The usage is follow,
if(headers_sent($file,$line)){
echo "header is already sent in {$file} at line {$line}";
}
this will spit out the cause of error as it occur. It saves me alot time when the such error is not so
obvious.
I hope my mistake and findings can save other people's some times. header() must be called before any actual output is sent
页:
[1]