如何避免PHP脚本在脚本中添加错误的位置


how to avoid php script adding the wrong location in a script?

所以我使用ajax内容,这很好,但我使用的php脚本是添加的链接的目录,我想要显示到我正在看的链接。所以基本上;

这里的php:

<?PHP
$category = "8";
$template = "Archives";
include("admin/show_news.php");
?>

链接为:
www.example.com/页面

但是脚本把它变成了:
www.example.com/页面/admin/show_news.php

,当它应该从;www.example.com/admin/show_news.php

我如何编辑脚本代码,使其找到正确的目录?

更改include("admin/show_news.php");to include("/admin/show_news.php");

不同之处在于在路径开头添加了斜杠,它被解释为从根目录开始的链接路径。

尝试更改

include("admin/show_news.php");

include($_SERVER['DOCUMENT_ROOT']."/admin/show_news.php");