ONLY FIRST WAY AJAX WORKS PHP GIVES TRUE THE OTHERS PHP GIVES FALSE...WELL?
Code:
function loginProcess() {
var userID = document.getElementById( "name" ).value;
var email = document.getElementById( "email" ).value;
var password = document.getElementById( "password" ).value;
ajax3 = new XMLHttpRequest();
//1st way GET NOT SECURE
ajax3.open("GET","loginProcess.php?userID="+userID+"&email="+email+"&password="+password,false);
ajax3.addEventListener("readystatechange", processResponse, true);
ajax3.send();
changeDisplay("loginRegisterDiv");
//2nd way POST JSON -- for secure really needed SSL
/*var myobj = { "userID":userID,"email":email,"password":password }; // p454
var jsonstring = JSON.stringify( myobj );
var postjson = "jsonstring="+encodeURIComponent( jsonstring );
ajax3.open("POST", "loginProcessJSON.php", true);
ajax3.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
ajax3.addEventListener("readystatechange", processResponse, true);
ajax3.send(postjson);
changeDisplay("loginRegisterDiv");*/
//3rd way POST plain -- for secure really needed SSL
/*var post1 = "userID="+userID+"&email="+email+"&password="+password;
ajax3.open("POST", "loginProcess.php", true);
ajax3.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
ajax3.addEventListener("readystatechange", processResponse, true);
ajax3.send(post1);
changeDisplay("loginRegisterDiv");*/
}
Code:
<?php // loginProcess.PHP
session_start();
$_SESSION["userID"]="";
$userID = $_REQUEST['userID'];
$password = $_REQUEST['password'];
$email = $_REQUEST['email'];
if ($_GET['userID']=="logout") {
$_SESSION["userID"]="0000000000000000000000000000000";
return;
}
if ((isset($_GET['userID'])) && (isset($_GET['password'])) && (isset($_GET['email'])))
{
if (($userID=="cust1") && ($password=="ju") && (($email=="9@es.com") || ($email=="9%40es.com")))
{
$_SESSION["userID"]=$_GET['userID'];
echo "true";
return;
} else {
echo "false";
return;
}
} else {
echo "false";
return;
}
?>
Code:
<?php // loginProcessJSON.PHP
session_start();
//http://stackoverflow.com/questions/8517071/send-json-data-via-post-ajax-and-receive-json-response-from-controller-mvc
$yourJSONString = $_POST["jsonstring"];
$array = json_decode($yourJSONString, true);
$userID = $array['userID'];
$password = $array['password'];
$email = $array['email'];
$_SESSION["userID"]="";
if ($_GET['userID']=="logout") {
$_SESSION["userID"]="0000000000000000000000000000000";
return;
}
if ((isset($_GET['userID'])) && (isset($_GET['password'])) && (isset($_GET['email'])))
{
if (($userID=="cust1") && ($password=="ju") && (($email=="9@es.com") || ($email=="9%40es.com")))
{
$_SESSION["userID"]=$_GET['userID'];
echo "true";
return;
} else {
echo "false";
return;
}
} else {
echo "false";
return;
}
?>
Bookmarks