【问题标题】:Error while executing php script执行php脚本时出错
【发布时间】:2016-09-12 13:38:26
【问题描述】:

我正在开发一个使用 php 构建的博客应用程序。

我有一个功能,如果没有博客条目,那么用户会看到一个链接,从那里他可以被引导到博客条目页面(我的项目中的 new.php)。
我可以成功显示链接,但我有一个小问题:

我的目录结构是 博客->(index.php new.php)

当我制作锚标记时,将 new.php 称为

$e = array(
        'title'=> 'No entries yet',
        'entry'=> '<a href=" blog/new.php">Post an entry here!</a>'
        );

在这种情况下,当我点击&lt;a&gt;标签时,浏览器地址栏显示地址为localhost:8080/blog/blog/new.php

如果将其更改为

$e = array(
        'title'=> 'No entries yet',
        'entry'=> '<a href="new.php">Post an entry here!</a>'
        );

然后地址栏显示:localhost:8080/new.php

在这两种情况下,我都无法显示页面。

【问题讨论】:

  • 使用绝对路径:"/blog/new.php".
  • 您是否在 localhost 的 8080 端口测试该站点?地址应该是什么?
  • 解决了伙计们 :) 感谢梅洛。

标签: php


【解决方案1】:

试试看:

$e = array(
    'title'=> 'No entries yet',
    'entry'=> '<a href="../blog/new.php">Post an entry here!</a>'
);

但还是使用绝对路径更好。它的性能要好一些。尝试使用$_SERVER['HTTP_HOST'],类似这样:

$e = array(
    'title'=> 'No entries yet',
    'entry'=> '<a href="http://' . $_SERVER['HTTP_HOST'] . '/blog/new.php">Post an entry here!</a>'
);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多