安全浏览时出现 simplexml_load_file 问题

发布于 2024-11-19 09:51:43 字数 1268 浏览 1 评论 0原文

当我安全地浏览客户端站点时,出现很多与 simplexml_load_file 函数有关的错误。下面是一个示例:

警告:simplexml_load_file() [function.simplexml-load-file]: https://xxxxxxxx /settings.xml:1:解析器错误:第 0 行 /xx/xx/xx/xx/xx/ 中的文档为空

该站点位于 SingleHop 的专用服务器上。仅当我使用 https:// 浏览网站时才会发生这种情况,并且在使用 http:// 浏览时工作正常。

似乎也可以使用 https:// 加载 XML 文件: https://consumerstrust.org/wp-content/plugins/easyfanpagedesign/framework /settings.xml

XML 是从一个类中解析出来的:

public function efpd_load_settings($xmlfile){
    $xmlparse=simplexml_load_file($xmlfile);
    $settings=array();
    $setint=0;
    foreach($xmlparse->option as $xml){
        $option[$setint]=(array)$xml;
        array_push($settings,$option[$setint]);
        $setint++;
    }
    return $settings;
}

并像这样运行:

$efpdxml=plugins_url('settings.xml',__FILE__); // plugins_url() is a WP function - returns the value just fine.
$efpdsettings=Efpd::efpd_load_settings($efpdxml);

这是常见的情况吗?还有什么可以修复的吗?如果您需要更多信息来帮助我解决此问题,请告诉我,我会提供。

谢谢。

I'm getting a lot of errors when I browse a clients site securely that have to do with the simplexml_load_file function. Here's an example:

Warning: simplexml_load_file() [function.simplexml-load-file]: https://xxxxxxxx/settings.xml:1: parser error : Document is empty in /xx/xx/xx/xx/xx/ on line 0

The site is on a dedicated server from SingleHop. It only happens when I browse the site with https://, and works fine when browsed with http://.

Seems to be loading the XML file just fine with https:// as well:
https://consumerstrust.org/wp-content/plugins/easyfanpagedesign/framework/settings.xml

The XML is parsed from a class:

public function efpd_load_settings($xmlfile){
    $xmlparse=simplexml_load_file($xmlfile);
    $settings=array();
    $setint=0;
    foreach($xmlparse->option as $xml){
        $option[$setint]=(array)$xml;
        array_push($settings,$option[$setint]);
        $setint++;
    }
    return $settings;
}

and ran like this:

$efpdxml=plugins_url('settings.xml',__FILE__); // plugins_url() is a WP function - returns the value just fine.
$efpdsettings=Efpd::efpd_load_settings($efpdxml);

Is this something that happens commonly? Also anything to fix it? If you need any more info to help me solve this just let me know and I will provide it.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

巨坚强 2024-11-26 09:51:43

我刚刚确认 file_get_contents 工作得很好。

    $content = file_get_contents("https://consumerstrust.org/wp-content/plugins/easyfanpagedesign/framework/settings.xml");
    if ( empty($content) ) {
        die('XML is empty');
    }
    $xml = simplexml_load_string($content);

编辑

使用 simplexml_load_filehttps URL 也对我有用。这只是一个替代方案。

I just confirmed file_get_contents works just fine.

    $content = file_get_contents("https://consumerstrust.org/wp-content/plugins/easyfanpagedesign/framework/settings.xml");
    if ( empty($content) ) {
        die('XML is empty');
    }
    $xml = simplexml_load_string($content);

Edit

Using simplexml_load_file with https URL also worked for me. This is only an alternative.

云雾 2024-11-26 09:51:43

我找到了自己的问题,但感谢那些试图帮助我的人。我很感激。

我的解决方案:

这是在 WordPress 中运行的,所以我真的应该将其发布在 WPSE 网站上,但如果他们不这样做,我不会责怪任何人不从该网站了解有关 WP 的所有信息。

函数 plugins_url() 不应该用于定义 XML 文件的路径,我应该使用 dirname(__FILE__).'/settings.xml' -这很明显地解释了为什么如果你知道 plugins_url() 是如何工作的,我完全忽略了它,但最终解决了我的问题。

I figured out my own problem, but thank you to those of you who tried helping me. I appreciate it.

My solution:

This was being run in WordPress, so I really should have posted this in the WPSE site, but I don't blame anyone for not knowing all about WP from this site if they didn't.

The function plugins_url() should not have been used to define the path to the XML file, I should have been using dirname(__FILE__).'/settings.xml' - which is pretty obvious as to why if you know how plugins_url() works, I overlooked it completely but in the end solved my problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文