我使用上面的PHP代码在www文件夹中使用Wamp创建本地页面,我想重定向到此页面,但是带有标题的重定向不起作用。
我收到消息:
页面未正确重定向。
Firefox检测到服务器正在以永远无法完成的方式重定向此地址的请求。有时可能会因禁用或拒绝接受cookie而导致此问题
有人知道怎么做吗?
我的代码:
$myFileName_with_no_lower_case = 'website_name'.$job.$ville;
$myFileName = strtolower($myFileName_with_no_lower_case);
$myFileHandle = fopen($myFileName, 'w') or die("can't open file");
$file_content = file_get_contents('./file_with_content_i_want_to_paste.php');
fwrite($myFileHandle,$file_content);
fclose($myFileHandle);
// eveything works fine until now
header("Location:".$myFileName);
答案 0 :(得分:0)
这是你的解决方案,我工具箱中最喜欢的功能之一:)
//==== Redirect... Try PHP header redirect, then Java redirect, then try http redirect.:
function redirect($url)
{
if (!headers_sent())
{ //If headers not sent yet... then do php redirect
header('Location: ' . $url);
exit;
} else
{ //If headers are sent... do java redirect... if java disabled, do html redirect.
echo '<script type="text/javascript">';
echo 'window.location.href="' . $url . '";';
echo '</script>';
echo '<noscript>';
echo '<meta http-equiv="refresh" content="0;url=' . $url . '" />';
echo '</noscript>';
exit;
}
} //==== End -- Redirect
答案 1 :(得分:0)
立即行动:
$myFileName_with_no_lower_case = $job.$ville;
$myFileName = strtolower($myFileName_with_no_lower_case);
$myFileHandle = fopen($myFileName, 'w') or die("can't open file");
$file_content = file_get_contents('./formulaire_artisans.php');
fwrite($myFileHandle,$file_content);
fclose($myFileHandle);
header("Location:".$myFileName);