0

Possible Duplicate:
Call php from javascript and return an array from php to Javascript function

i am having an php code for verification of User in XML

For Eg: ValLogin.php

<?php
$userName =  $_REQUEST["username"];
$password =  $_REQUEST["password"];
$iCount = 0;
$loginArray = array();
$xml = simplexml_load_file("Logintest.xml");
for ($i=0;$i<2;$i++)
{
    foreach($xml->Username[$i]->attributes() as $a => $b)
    {
        $loginArray[$iCount] = $b;
        $iCount++;
    }
    if($userName == $loginArray[0] && $password == $loginArray[1])
    {
        header("Location: EHP_Configuration.html");
        return ;
    }
    $iCount = 0;
}
echo "<SCRIPT LANGUAGE='javascript'>alert('asd')</SCRIPT>";
header("Location: Login.html");
?> 

HTML

<form method = "post" action = "ValLogin.php">
</form>

echo does not work as expected. it directly shows redirect to Login

How can i get the message invalid username/Login?

3
  • Can you please also provide an example of Logintest.xml? Amongst other things the way you iterate through the xml doc seems ...odd ;-) Commented Oct 20, 2009 at 7:55
  • Logintest.xml <?xml version="1.0" encoding="ISO-8859-1"?> <Users> <Username User = "Admin" Password = "Password"/> <Username User = "Client" Password = "Client" /> </Users> Commented Oct 20, 2009 at 11:08
  • Extending VolkerK's note, use SimpleXMLElement::xpath() (php.net/manual/en/simplexmlelement.xpath.php) rather than looping. Looking up a user will take 1 line: $xml->xpath("//Username[@User='$username' and @Password='$password']") Commented Oct 21, 2009 at 4:14

1 Answer 1

1

You cannot send HTML/Data before sending the header, so you'll have to send the javascript-alert inside the "Login.html".

Besides that you really should embrace your Javascript code with

<script type="text/javascript">
         alert('asd');
</script>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.