如何防止PHP中的动态链接更改?

时间:2017-12-03 02:03:54

标签: php wordpress

我在ASP.NET MVC中开发,所以请原谅我在PHP和WordPress方面缺乏基础知识。我们有一个WordPress网站,其中页脚中的条款和条件链接在一个页面上打破,但在另一个页面上工作。

在我们的主页(http://www.ourdomain.com)上有一个链接,当我将鼠标悬停在其上时,我可以在Chrome中看到它从以下位置动态更改:

ourdomain.com/wp-content/themes/mm/pdf/Terms.pdf

为:

www.ourdomain.com/wp-content/themes/mm/pdf/Terms.pdf

当我查看页面的来源时,锚标记是这样的:

<a href="wp-content/themes/mm/pdf/Terms.pdf">Terms</a>

这样可以正常工作并呈现必要的pdf文件。我们还有另一个网址(http://www.ourdomain.com/contact),其条款和条件链接也可以更改:

ourdomain.com/contact/wp-content/themes/mm/pdf/Terms.pdf

为:

www.ourdomain.com/contact/wp-content/themes/mm/pdf/Terms.pdf

当我查看页面的来源时,锚标记如下:

<a href="wp-content/themes/mm/pdf/Terms.pdf">Terms</a>

我可以访问该网站的整个网站和MySQL数据库。我可以更改哪些内容以阻止链接将内容添加到网址?这些链接通常存储在数据库中吗?

1 个答案:

答案 0 :(得分:0)

因为您没有输入完整路径,因此地址是您网页地址的计数。正如您所看到的那样联系

/ 将指向域名

./ 将指向当前网址

示例example.com/contact

<a href="/somefolder/file.pdf">

将指向http://example.com/somefolder/file.pdf

<a href="./somefolder/file.pdf">

将指向http://example.com/contact/somefolder/file.pdf

为避免这种情况,您可以输入完整的网址。

如果链接在您的主题中,则在wordpress的情况下,您可以使用函数get_stylesheet_directory_uri()获取主题的完整网址。

<a href="<?php echo get_stylesheet_directory_uri(); ?>/pdf/Terms.pdf">Terms</a>