irken Posted December 18, 2006 Share Posted December 18, 2006 Hi.I just can't figure this one out.. for some reason, even if field is passed to the script, it takes me to the index page. The line if ($_GET['x'] and $_GET['y'] and $_GET['field']) is not working all the time.Here's my setPosition.php[code]<?php include($_SERVER['DOCUMENT_ROOT'] . '/includes/browsercheck.php'); header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); session_start(); if ($_SESSION['username']) { $ping = "pong"; include($_SERVER['DOCUMENT_ROOT'] . '/includes/database.php'); $username = $_SESSION['username']; $password = $_SESSION['password']; $hostname = $_SESSION['hostname']; if ($_GET['x'] and $_GET['y'] and $_GET['field']) { $x = $_GET['x']; $y = $_GET['y']; $field = $_GET['field']; $connection = new mysql(); $connection->connect(); $query = "SELECT field FROM `users` WHERE chatting='1'"; $result = $connection->query($query); while ($player = mysql_fetch_array($result)) { if ($player[field] == $field) { echo "BADMOVE"; exit; } } // Set up the query string. $query = "UPDATE `users` SET x='$x', y='$y', field='$field', chatting='1' WHERE username='".$username."'"; $result = $connection->query($query); //$connection->disconnect(); echo "MOVEOK"; exit; } else // if ($_GET['x'] and $_GET['y'] and $_GET['field']) { Header('Location: /index.php'); exit; } } else // if ($_SESSION['username']) { Header('Location: /index.php'); }?>[/code]And here's my meToField function.[code]/* Moves us to the specified field */function meToField(idx){ var setPosition; try { setPosition = new ActiveXObject("Microsoft.XMLHTTP"); } catch (Exception) { // Something went wrong alert("Your browser broke!"); return false; } try { // Get the Field DIV. var objField = document.getElementById('Field_' + idx); if (objField) { objField = objField.style; var objMeField = document.getElementById('Player_Me'); if (objMeField) { setPosition.onreadystatechange = function() { if (setPosition.readyState == 4) // 4 = complete { if (setPosition.responseText == "MOVEOK") { //objMeField = objMeField.style; with (objMeField.style) { left = objField.left; top = objField.top; zIndex = idx; return true; } } else { alert('responseText: ' + setPosition.responseText); if (setPosition.responseText == "BADMOVE") { return false; } } } return true; } // Set our position. setPosition.open("GET", "setPosition.php?x=" + objField.left.replace("px", "") + "&y=" + objField.top.replace("px", "") + "&field=" + idx, true); setPosition.send(null); return true; } else { alert('Error: document.getElementById(Player_Me)'); return false; } } else { alert('Error: document.getElementById(Field_idx)'); return false; } } catch (Exception) { // Display error. alert('Exception: ' + Exception.message); return false; }}[/code]Everything here workes, if x or y is not passed as 0 in this line:[code]setPosition.open("GET", "setPosition.php?x=" + objField.left.replace("px", "") + "&y=" + objField.top.replace("px", "") + "&field=" + idx, true);[/code]I can't imagine why. Response text prints out the contents of the index page which would mean it got to here:[code] else // if ($_GET['x'] and $_GET['y'] and $_GET['field']) { Header('Location: /index.php'); exit; }[/code]And that the "if" has failed. But field is being passed to the script.[b]EDIT:[/b] Hmm, upon further testing, it seems that it doesn't want to accept X being 0 or Y being 0. How do I fix this? I thought $_GET['x'] would accept anything. Quote Link to comment https://forums.phpfreaks.com/topic/31119-solved-get-request-acting-weird/ Share on other sites More sharing options...
redbullmarky Posted December 18, 2006 Share Posted December 18, 2006 0 is classed as a 'false' value so if x is 0 in the URL, $_GET['x'] when using 'if' will return false.for what you want to do, try:[code]if (isset($_GET['x']) and isset($_GET['y']) and isset($_GET['field']))[/code] Quote Link to comment https://forums.phpfreaks.com/topic/31119-solved-get-request-acting-weird/#findComment-143694 Share on other sites More sharing options...
irken Posted December 18, 2006 Author Share Posted December 18, 2006 [quote author=redbullmarky link=topic=119127.msg487414#msg487414 date=1166460454]0 is classed as a 'false' value so if x is 0 in the URL, $_GET['x'] when using 'if' will return false.for what you want to do, try:[code]if (isset($_GET['x']) and isset($_GET['y']) and isset($_GET['field']))[/code][/quote]Aha! I wasn't aware of that. That fixed it - thanks alot. Gave me headaches :D Quote Link to comment https://forums.phpfreaks.com/topic/31119-solved-get-request-acting-weird/#findComment-143697 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.