xbox-scene.com - your xbox news information source
Quick Links: Main Forums | Xbox360 Forums | Xbox1 Forums | PS3 Forums
Xbox-Scene Forum Help  Search Xbox-Scene Forums   Xbox-Scene Forum Members   Xbox-Scene Calendar

Giganews Usenet Offers: +1150 days binary retention, 99%+ Completion, and Unlimited Speed/Access!

360 ODD Emulators: X360 Key $99 | Wasabi360 FAT $99 | Wasabi360 Slim $99
C4E's iXtreme Burner MAX Drive: LiteOn iHAS124 DROPPED TO JUST $17


Welcome Guest ( Log In | Register )

 Forum Rules Rules
 
Reply to this topicStart new topic
> Php + Ajax Help
taikwondoejoe
post Aug 12 2006, 06:05 AM
Post #1


X-S Expert
***

Group: Members
Posts: 624
Joined: 13-January 06
From: Michigan
Member No.: 268293
Xbox Version: none
360 version: v1 (xenon)



Trying to make an ajax login I found here work with cookies.
Problem is the cookie isn't setting.

Ajax
CODE

<script language="javascript" type="text/javascript">
    var phpscript = 'login.php';
    
    function createRequestObject() {
    
        var req;
    
        if(window.XMLHttpRequest){
            req = new XMLHttpRequest();
        } else if(window.ActiveXObject) {
            req = new ActiveXObject("MS.XMLHTTP");
        } else {
            alert('There was a problem creating the XMLHttpRequest object');
        }
    
        return req;
    
    }
    var http = createRequestObject();
    
    
    function sendRequestPost() {
        
        var user = document.getElementById('username').value;
        var pass = document.getElementById('password').value;
    
        http.open('post', phpscript);
        http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        http.onreadystatechange = handleResponsePost;
        http.send('username='+ user +'&password='+ pass);
    
    }
    
    
    function handleResponsePost() {
    if(http.readyState == 1){
            document.getElementById("response").innerHTML = "Processing login..";
        } else if(http.readyState == 4 && http.status == 200){
            var response = http.responseText;
    
            if(response) {
                document.getElementById("response").innerHTML = response;
            }
    
        }
    }    
</SCRIPT>


Login.php
CODE

<?php
//mysql connect is up hurr
ob_start();

$username = $_POST['username'];
$password = $_POST['password'];

$query = mysql_query("SELECT * FROM users WHERE username='". $username ."' AND password='". $password ."'");
$result = mysql_num_rows($query);
$row = mysql_fetch_array($query);
$blah = $row["username"];

if(isset($_COOKIE[$blah])){

if ($result == 1){
    $_POST["username"] = $row["username"];

setcookie("username", $row["username"],time()+(60*60*24*5), "/", "");
setcookie("password", $row["password"],time()+(60*60*24*5), "/", "");


    echo 'Logged in, '. $row["username"];
}else{
    echo 'Wrong username or password.';
}

}else{
echo("<DIV id=\"response\">
<form method=\"post\" action=\"\">
<input name=\"username\" value=\"Username\" type=\"text\" name=\"username\" id=\"username\" style=\"margin-bottom: 1px;\" onfocus=\"this.value=''\">
<input name=\"password\" value=\"******\" type=\"password\" name =\"password\" id=\"password\" style=\"margin-bottom: 1px;\" onfocus=\"this.value=''\">
<input name=\"button\" type=\"button\" id=\"submit\" onClick=\"sendRequestPost();\" name=\"submit\" value=\"Login\" />
</form></DIV>");
}
?>


Been messing with this for hours, so I think I'm just missing something really obvious.
I'm not looking for some copy and paste code so itll work, just an explanation on what I'm doing wrong. XS may not be the best place to post this, but I think someone here will be able to help me out.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post





Reply to this topicStart new topic

 

Lo-Fi Version Time is now: 19th June 2013 - 11:44 AM