【问题标题】:Redirect to a local webpage created dynamically in www Wamp folder重定向到在 www Wamp 文件夹中动态创建的本地网页
【发布时间】:2011-08-30 08:08:41
【问题描述】:

我使用上面的 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);

【问题讨论】:

  • @Pekka 你是对的,谢谢!但是现在我遇到了另一个问题(相关,所以我不会更改帖子)。

标签: php file redirect wamp webpage


【解决方案1】:

这是您的解决方案,是我工具箱中我最喜欢的功能之一 :)

//==== 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

【讨论】:

  • 感谢您的回答,但我收到的信息与往常一样。
  • 页面重定向不正确。 Firefox 检测到服务器正在以永远不会完成的方式重定向对该地址的请求。此问题有时可能是由禁用或拒绝接受 cookie 引起的
  • 使用 if(file_exists($myFileName)){ header here } else { echo '文件不存在'; } 以确保您的文件确实存在。也尝试从地址栏访问文件,以确保可以通过网络访问文件(不应该是 wamp 上的问题)
  • 哦,那个烦人的错误......你正在重定向到同一个页面......一个无限循环。如果您需要重定向到同一个文件,请在重定向上执行特殊的 GET,这样您就不会在重定向后被重定向
  • 我已经检查了文件夹并且文件存在。当我尝试使用地址栏访问它时,我收到了相同的消息。
【解决方案2】:

现在工作:

    $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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-23
    相关资源
    最近更新 更多