每次登录都会进入shop.php页面。我很困惑,我做错了。有人在这里为我解决这个问题吗?感谢
<?php
$xml = simplexml_load_file("info.xml");
if (isset($_POST['submit'])) {
$user=$_POST["username"];
$pass=$_POST["password"];
$account=$_POST["accounttype"];
foreach ($xml->author as $author) {
if ($user==$author->aName && $pass==$author->apassword &&
$account==$author->$author->{"Buyer"}) {
session_start();
$_SESSION['simple_login'] = $user;
$_SESSION['pass_login'] = $pass;
header("location:shop.php");
exit();
} elseif ($user==$author->aName && $pass==$author->apassword &&
$account==$author->$author->{"Seller"}) {
session_start();
$_SESSION['simple_login'] = $user;
$_SESSION['pass_login'] = $pass;
header("location:admin.php");
exit();
} else {
$error = '<div class="alert alert-danger" role="alert"><p>
<strong>Invalid credentials. Try again!</div>';
}
}
}
?>
我的XML是
<?xml version="1.0"?>
<authorList>
<author>
<aName>bbb</aName>
<apassword>bbb</apassword>
<aemail>email@yahoo.com</aemail>
<aphone>111</aphone>
<aaccounttype>Buyer</aaccounttype>
</author>
<author>
<aName>sss</aName>
<apassword>sss</apassword>
<aemail>test@yahoo.com</aemail>
<aphone>222</aphone>
<aaccounttype>Seller</aaccounttype>
</author>
</authorList>
答案 0 :(得分:0)
如果我理解正确,您只需更改两个if
条件:
if (... $account == $author->$author->{"Buyer"})
if (... $account == $author->$author->{"Seller"})
应该成为:
if (... $account == $author->aaccounttype)
if (... $account == $author->aaccounttype)
您的$_POST
变量accounttype
应分别映射到Buyer
和Seller
。
答案 1 :(得分:0)
您似乎在检查传入的帐户类型是否与记录中的类型匹配,您只需要检查XML文件中的值是买方还是卖方......
if ($user==$author->aName && $pass==$author->apassword &&
$author->aaccounttype == "Seller" ) {
或
if ($user==$author->aName && $pass==$author->apassword &&
$author->aaccounttype == "Buyer" ) {