我有两个 xml 文件,多亏了 Lawrance,我能够将登录用户的 xml 详细信息解析到 admin_panel 现在我正在尝试迭代第二个 xml 文件,该文件仅共享 unique_ref 作为参考,因为我是 PHP 和 xml 的新手我正在努力获得我想要的结果。xml中的登录是
<MYData>
<login_details>
<unique_ref>1-61</unique_ref>
<login_name>tomme</login_name>
<login>me</login>
<password>me</password>
<file1>Test</file1>
<file2/>
<file3/>
<file4/>
</login_details>
<login_details>
<unique_ref>1-63</unique_ref>
<login_name>tony</login_name>
<login>tony</login>
<password>tony</password>
<file1>Test1</file1>
<file2/>
<file3/>
<file4/>
</login_details>
</MYData>
和用户图像的第二个 xml 文件
<MYData>
<mydata_images>
<unique_ref>1-61</unique_ref>
<image1>IMG_0125.JPG</image1>
<image2>IMG_0122.JPG</image2>
<stat_date>2013-02-03</stat_date>
<path_file>C:\DATA\\documents\page_1.pdf</path_file>
</mydata_images>
<mydata_images>
<unique_ref>1-61</unique_ref>
<image1>IMG_0127.JPG</image1>
<image2>IMG_0128.JPG</image2>
<stat_date>2013-04-03</stat_date>
<path_file>C:\DATA\\documents\page_3.pdf</path_file>
</mydata_images>
<mydata_images>
<unique_ref>1-63</unique_ref>
<image1>2.THEMOUNT.JPG</image1>
<image2>1.THE-MOUNT.JPG</image2>
<stat_date>2013-01-03</stat_date>
<path_file>C:\DATA\\documents\page_2.pdf</path_file>
</mydata_images>
<mydata_images>
<unique_ref>1-61</unique_ref>
<image1>IMG_0109.JPG</image1>
<image2>IMG_0112.JPG</image2>
<stat_date>2013-05-03</stat_date>
<path_file>C:\DATA\\documents\page_4.pdf</path_file>
</mydata_images>
</MYData>
我想显示登录用户的图像和我尝试使用 array_intersect 的 pdf 图像,但我一直收到错误,这是我一直在玩的 admin_panel
<?php
session_start();
//logout
$mydata2 = simplexml_load_file("xml/mydata_images.xml");
if(isset($_GET['logout'])){unset($_SESSION['logged_in']);session_destroy();}
//check login
if(isset($_SESSION['logged_in']) && $_SESSION['logged_in']==true){
//json decode user details from session into an array
$user_details = json_decode($_SESSION['user_details'],true);
$id = json_decode($_SESSION['id'],true);
//debug your values
$unique_ref =$mydata2->mydata_images;
echo $unique_ref;
$result = array_intersect($user_details,$unique_ref );
$unique_ref =$user_details["unique_ref"];
//foreach ($mydata2 as $unique_ref => $result){
//print "$unique_ref = $result\n";
// print_r($result);
//}
echo '<pre>'.print_r($user_details,true).'</pre>';
echo $id;
echo $user_details["login"];
echo $unique_ref;
echo $result;
/*
Array
(
[unique_ref] => 1-61
[login_name] => tomme
[login] => me
[file1] => Test
[file2] => Array
(
)
[file3] => Array
(
)
[file4] => Array
(
)
)
*/
echo '<a href="?logout">logout</a>';
}else{
exit(header("Location: ./login.php"));
}
?>