o0110o wrote:I followed your directions, and I placed the new code accordingly:
There is a lesson to be learnt here: if you had replaced my "Handle invalid format error" comment with code that actually handled or otherwise indicated the invalid format error, you would have detected early on that there was a mismatch between the format that I guessed was correct and the actual format 🙂
In the code that you eventually got to work, you still have a similiar problem: you just urlencode the result, without checking for success or failure. You should consider throwing an exception or returning false to indicate failure, and then make sure that you either eventually catch the exception if it is thrown, or that the caller checks for failure.
halojoy wrote:I make the urlencode on the result, just before return it.
This might be fine in this case, but generally speaking it is a bad idea since it results in loss of generality for the function (even though this can be reversed with urldecode), considering that the function is named getLocation rather than say, getUrlEncodedLocation.
EDIT:
o0110o wrote:So all I would need is a form to submit an IP to the script? Is that what your IP feature is for?
Actually, I thought that your use of $results as the parameter was a typographical error that halojoy fixed. It makes more sense to have $ip as the parameter as it makes the function more flexible: you can provide an IP address as an argument, or you can provide no arguments and thus just use $_SERVER['REMOTE_ADDR'].
In this sense, you do not need a form to submit an IP address to the script, but you can make it such if you want.