执行php脚本时出错

时间:2016-09-12 13:38:27

标签: php

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

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

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

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

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

在这种情况下,当我点击<a>标记时,浏览器地址栏会将地址显示为 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

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

1 个答案:

答案 0 :(得分:0)

试一试:

$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>'
);
相关问题