安全浏览时出现 simplexml_load_file 问题
当我安全地浏览客户端站点时,出现很多与 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我刚刚确认 file_get_contents 工作得很好。
编辑
使用
simplexml_load_file
和https
URL 也对我有用。这只是一个替代方案。I just confirmed file_get_contents works just fine.
Edit
Using
simplexml_load_file
withhttps
URL also worked for me. This is only an alternative.我找到了自己的问题,但感谢那些试图帮助我的人。我很感激。
我的解决方案:
这是在 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 usingdirname(__FILE__).'/settings.xml'
- which is pretty obvious as to why if you know howplugins_url()
works, I overlooked it completely but in the end solved my problem.