Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder godofreality's Avatar
    Join Date
    Jan 2009
    Posts
    234
    Thanks
    1
    Thanked 15 Times in 15 Posts

    getting different result live than i am locally

    ok when i run this all locally everything works how it is suppose to however when i run it live i end up getting a NULL value to see it in action http://aodrops.com it is the login form username/password dum matter since the data isn't passing properly

    here is the handler.php page producing the output
    PHP Code:
    <?php
        session_start
    ();
        
    var_dump($_POST);
        
    $data json_decode($_POST['data'], true);
        echo 
    '<hr />';
        
    var_dump($data);
    ?>
    the javascript responsible for collecting and passing the data onto the server
    Code:
    function outgoing(action, data){
    	var breaker = new Date();
    	var debug = document.getElementById('debug');
    	debug.innerHTML = '';
    	var ajax = false;
    	if(window.XMLHttpRequest){
    		ajax = new XMLHttpRequest();
    	} 
    	else if(window.ActiveXObject){
    		ajax = new ActiveXObject('Microsoft.XMLHTTP');
    	}
    	if(ajax){
    		ajax.open('POST', 'handler.php?action='+action+'&breaker='+breaker.getTime());
    		ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    		ajax.onreadystatechange = function(){
    			if (ajax.readyState==4){
    				debug.innerHTML += ajax.responseText;
    			}
    		}
    		ajax.send('data='+data);
    	}
    }
    			
    function handler(action,src){
    	var output = new Array();
    	var gojuice = 'yes';
    	var firstfail = 'none';
    	debug.innerHTML = '';
    	switch(action){
    		case 'registration':
    			var data = src.parentNode.getElementsByTagName('input');
    			for(f = 0; f < data.length; f++){
    				if(data[f].value != ''){
    					data[f].style.background = '#ffffff';
    					output[f] = new Array(data[f].id,data[f].value);
    				}
    				else{
    					gojuice = 'no';
    					if(firstfail == 'none'){
    						firstfail = data[f];
    					}
    					data[f].style.background = '#cccccc';
    				}
    			}
    			if(data[1].value !== data[2].value && firstfail == 'none'){
    				data[2].style.background = '#cccccc';
    				gojuice = 'no';
    				firstfail = data[2];
    			}
    		break;
    					
    		case 'login':
    			var data = src.parentNode.getElementsByTagName('input');
    			for(f = 0; f < data.length; f++){
    				if(data[f].value != ''){
    					data[f].style.background = '#ffffff';
    					output[f] = new Array(data[f].id,data[f].value);
    				}
    				else{
    					gojuice = 'no';
    					if(firstfail == 'none'){
    						firstfail = data[f];
    					}
    					data[f].style.background = '#cccccc';
    				}
    			}
    		break;
    	}
    	if(gojuice == 'yes'){
    		outgoing(action,JSON.stringify(output));
    	}
    	else{
    		firstfail.focus();
    	}
    }
    lastly the login form
    Code:
    <div id="login" class="content" style="margin-top: 10px;">
    	<span class="titlebar">Deity Citadel Login</span>
    	<span class="form">Username:<input type="text" id="user" /></span>
    	<span class="form">Password:<input type="password" id="password" /></span>
    	<span class="menubutton" style="display: block; margin: auto; margin-top: 5px; margin-bottom: 5px;" onclick="handler('login',this)">LOGIN</span>
    </div>
    Last edited by godofreality; 06-21-2013 at 06:02 AM.
    woot found the avatar options...i swear they didn't exist b4

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,474
    Thanks
    13
    Thanked 361 Times in 357 Posts
    try switching off magic_quotes_gpc (good idea anyways).

    Edit: doh, you do not have a data item in your post (as you can see from the dump)


    though I wouldn’t use an array of arrays. better stick to the usual name-value pairs (easier to handle in PHP).
    Last edited by Dormilich; 06-21-2013 at 07:59 AM.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    No, you were right in the first place dormilich. Disable the magic_quotes_gpc or manually strip them recursively.
    The output I see is as such: string(39) "[[\"user\",\"a\"],[\"password\",\"a\"]]" , which is incorrect. That should be: string(31) "[["user","a"],["password","a"]]" which indicates that magic_quotes_gpc is enabled.
    The difference is that the first with the escaped quotes cannot be decoded by json_decode which then returns null for its results.

    You should probably use a form that doesn't require JS as well. That's the very first step to verifying potential problems.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •