1 回答

TA貢獻1804條經驗 獲得超8個贊
在 foreach 循環中,您僅檢查 XML 數據中的第一個條目,如果不匹配則退出。你需要做這樣的事情:
<?php
$emailid = $_POST["email"];
$pass? ? = $_POST["password"];
if (isset($_REQUEST['ok']))
{
? ? $xml2 = simplexml_load_file('storedata.xml');
? ? $validLogin = false;
? ? foreach ($xml2->data as $user)
? ? {
? ? ? ? // for every user node
? ? ? ? if ($user->email2 == $emailid && $user->pass2 == $pass)
? ? ? ? {
? ? ? ? ? ? $validLogin = true;
? ? ? ? ? ? break;
? ? ? ? }
? ? }
? ? if ($validLogin)
? ? {
? ? ? ? header("Location: index.html", true, 301);
? ? ? ? exit();
? ? }
? ? else
? ? {
? ? ? ? echo 'Sorry, email and passwords dont match.<br><p>Please go back to the login page and enter correct information.</p>';
? ? }
? ??
? ? if (($_POST["email"] == "[email protected]") && ($_POST["password"] == "teamproject55"))
? ? {
? ? ? ? header("Location: backstore_inventory_ben.html", true, 301);
? ? ? ? exit();
? ? }
}
另外,如果您的 XML 文件中有多個條目,您可能需要檢查DOM,特別是DOMXpath,這樣您就可以搜索匹配項,而不必遍歷整個 ist 并進行字符串匹配。
- 1 回答
- 0 關注
- 121 瀏覽
添加回答
舉報