0

customer.xml

<?xml version="1.0"?>

<customers>
    <customer>
        <ID>C1</ID>
        <FirstName>Kah Hon</FirstName>
        <SurName>Wong</SurName>
        <Email>gahhon@hotmail.com</Email>
        <Password>081292</Password> 
    </customer>
</customers>

login.js

var xHRObject = false;

if (window.XMLHttpRequest)
    xHRObject = new XMLHttpRequest();
else if (window.ActiveXObject)
    xHRObject = new ActiveXObject("Microsoft.XMLHTTP");

function reset() {
    document.getElementsByName('txtEmail').value = "";
    document.getElementsByName('txtPassword').value = "";
}

function login() 
{
    var email = document.getElementsByName('txtEmail').value;
    var pass = document.getElementsByName('txtPassword').value;

    xHRObject.open("GET", "login.php?id=" + Number(new Date) +"&email=" + email + "&pass=" + pass, true);
    xHRObject.onreadystatechange = function() {
        if (xHRObject.readyState == 4 && xHRObject.status == 200)
            document.getElementById('information').innerHTML = xHRObject.responseText;
        }
    xHRObject.send(null); 
}

login.php

<?php
    $xmlFile = "customer.xml";
    $isFound = "";
    $dom = DOMDocument::load($xmlFile);
    $customer = $dom->getElementsByTagName("customer"); 

    foreach($customer as $node) { 
        $email = $node->getElementsByTagName("Email");
        $email = $email->item(0)->nodeValue;

        $pass = $node->getElementsByTagName("Password");
        $pass = $pass->item(0)->nodeValue; 

        if($_GET["email"] == $email && $_GET["pass"] == $pass)
            $isFound = true;
        else
            $isFound = false;
    } 

    if ($isFound == true) {
        ECHO ("<script type='text/javascript'>");
        ECHO ("document.location.href = 'bidding.htm'");
        ECHO ("</script>");
    }
    else {
        ECHO ("<script type='text/javascript'>");
        ECHO ("alert('Login Failure!')");
        ECHO ("</script>");
    }
?>

login.htm

        <form>
            <div class="form">
                <fieldset>
                    <legend>Login Details</legend>
                    <p style="text-align:left;">* Required Fields</p>
                    <br>
                    <table>
                        <tr>
                            <td style="text-align:right;">Email <label>*</label></td>
                            <td><input type="email" name="txtEmail" class="textbox" placeholder="Enter Your Email Address"
                                oninvalid="this.setCustomValidity('Please Enter Your Email!')" oninput="setCustomValidity('')" required /></td>
                        </tr>
                        <tr>
                            <td style="text-align:right;">Password <label>*</label></td>
                            <td><input type="password" name="txtPassword" class="textbox" placeholder="Enter Your Password"
                                oninvalid="this.setCustomValidity('Please Enter Your Password!')" oninput="setCustomValidity('')" required /></td>
                        </tr>
                        <tr>
                            <td></td>
                            <td>
                                <input type="submit" name="btnLogin" value="Login" onclick="login();" />
                                <input type="submit" name="btnReset" value="Reset" onclick="reset();" />
                            </td>
                        </tr>
                    </table>
                </fieldset>
            </div>      
        </form>

        <div id="information"></div>

So I do exactly same as my lecture example. But I couldn't get the error message or the page redirect.
I am not sure is it the problem at login.js

Please advise.
Thanks

2
Contributors
3
Replies
22
Views
6 Months
Discussion Span
Last Post by gahhon
1

Are you passing passwords with GET? If so, don't.

//EDIT

Really, don't

Edited by diafol

0

This is just the begining of my assignment only.
Thus, I go for simple design and functionality first before I enhance them.s

0

So the scenario of the project is like this.

I am using XMLHttpsRequest to open login.php to check the data against with XML.

But I'm have no idea how to check like if the data match, then redirect to another page. Else, prompt error message.

any advise will be appreciate. Thankss

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.