使用XML和PHP登录表单(调用多个会话)

时间:2014-04-15 04:33:37

标签: php xml session login

您好〜我正在为我的购物车分配创建一个登录表单,任务是从xml文件中检索每个成员的数据并在我的菜单页面上显示。所以这是我的

**Login.php** 

    <?php
    session_start();
    if(isset($_POST['login'])){
        $username = preg_replace('/[^A-Za-z]/', '', $_POST['username']);
        $password = md5($_POST['password']);
        $xml = simplexml_load_file("members.xml");
        $member = $xml->xpath('/members/member[username="'.$username.'"]');

    foreach($member as $memberinfo){ 
    if($memberinfo->username == $username && $memberinfo->password == $password){
    $_SESSION['username']=$username;

    // The coding works perfectly until this point. It wont show the details on menu page if i put these codes .

    $_SESSION['address']=$memberinfo->address;    
    $_SESSION['phonenumber']=$memberinfo->phonenumber; 
    $_SESSION['fullname']=$memberinfo->address;          
    header('Location: Menu.php');
    }
    }
    }
    ?>

这是Menu.php页面:

<?php 
session_start();

    if(isset($_SESSION['username'])){                            
 echo " Hello " .
 $_SESSION['username'] .
 $_SESSION['address'] .
 $_SESSION['phonenumber'] .
 $_SESSION['fullname'] ; }

?>  

这是我的members.xml

**members.xml**
<?xml version="1.0" encoding="utf-8"?>
<members>
  <member>
    <username>www</username>
    <fullname>www</fullname>
    <password>4eae35f1b35977a00ebd8086c259d4c9</password>
    <address>www</address>
    <phonenumber>www</phonenumber>
  </member>
  <member>
    <username>we</username>
    <fullname>we</fullname>
    <password>ff1ccf57e98c817df1efcd9fe44a8aeb</password>
    <address>we</address>
    <phonenumber>we</phonenumber>
  </member>
</members>

其他信息:我尝试使用关联数组,但仍未显示详细信息。如果有人知道解决方案,你会帮助我吗?谢谢:')

0 个答案:

没有答案