在我的本地 wamp 服务器上运行它可以让我ERR_CONNECTION_RESET
尝试通过浏览器访问 .php 文件。这里发生了什么?
<?php
$catalog = simplexml_load_file('http://www.w3schools.com/xml/cd_catalog.xml');
session_start();
if (!isset($_SESSION['selection'])) {
$_SESSION['selection'] = array();
}
array_push($_SESSION['selection'], $catalog->CD[0]);
?>
这是输出的一部分var_dump($catalog)
object(SimpleXMLElement)[1]
public 'CD' =>
array (size=26)
0 =>
object(SimpleXMLElement)[2]
public 'TITLE' => string 'Empire Burlesque' (length=16)
public 'ARTIST' => string 'Bob Dylan' (length=9)
public 'COUNTRY' => string 'USA' (length=3)
public 'COMPANY' => string 'Columbia' (length=8)
public 'PRICE' => string '10.90' (length=5)
public 'YEAR' => string '1985' (length=4)
1 => [...]
编辑:按照建议从 apache 日志中找到这个:
[Tue Apr 02 09:34:54 2013] [error] [client 127.0.0.1] PHP Fatal error: Uncaught exception 'Exception' with message 'Serialization of 'SimpleXMLElement' is not allowed' in [no active file]:0\nStack trace:\n#0 {main}\n thrown in [no active file] on line 0
所以我想问题是php的会话序列化不允许SimpleXMLElements。我会保存一个索引或其他东西。