Script works online, but not locally??
Posted by Chris_Isaac (Chris Isaac), 4 February 2004Hi
I have a script which can perform a search on Post Code, Name or Town. The script is up and running on line and works fine. I have set up the same database and script on my local machine for test purposes, but now the town search doesn't work, where the Post Code and Name does.
I think I've narrowed it down to the segment below, can you see anything which may not cause the town search to work??
Posted by admin (Graham Ellis), 4 February 2004So .. can I clarify / ask...
a) The problem is NOT in the SQL but in the conditional test??
b) Where you say "does not work", do you mean that it prints nothing, or it prints the wrong message (such as the "Sorry" that's there on the else clause?). It doesn't print out "pcode bit working" by any chance does it I could explain that one
Posted by Chris_Isaac (Chris Isaac), 5 February 2004"doesn't work" doesn't give a lot of information does it
When you do a search on town, it does bring up the list of options, eg, if you did a search on Newport it would give you a list like:
etc, etc, etc
The above are hyperlinks which would then list all establishments in Newport, Gwent or whatever. This is where it fail, it doesn't list any establishment at all, but if I search on postcode it does, and again you can search on name and thats fine too.
All I did when I installed it locally was to change the paths to the local machine, I would have thought if this was wrong none of the searches would work.
Posted by admin (Graham Ellis), 5 February 2004You've still not told me which (if any) of those print statements came out on the failed runs. I'm suspecting a differing PHP version / setting of register_globals between the servers, as I've noticed that $incode isn't copied out of $_GET like the other variables are ...
Posted by Chris_Isaac (Chris Isaac), 5 February 2004Sorry, it is in the code above, but not very clear:
9 line down prints out ok:
Line 15, 1st test prints out ok:
line 23 prints ok :
The only line that doesn't print is line 19 :
I'll have a look at the global varibles when in work tomorrow and see if I can spot anything.
Posted by admin (Graham Ellis), 5 February 2004Ah - sorry - I had read those comments differently. Then it's got a true value that perhaps it shouldn't have in $incode on one machine, but not on the other? Once a condition in an if... elseif ... else sequence is matched, it won't try others. So as soon as it finds a postcode, it ignores the town it was given as that's a lower precendence operator.
Is the script triggered by the same referer page on both machines? Does one trigger form include an incode entry and the other not? Another possibility for you to look at.
Posted by Chris_Isaac (Chris Isaac), 5 February 2004Its all triggered from the same script, whats confusing me is that the postcode search works, and so does the name, its just the town search that has the problem.
I've tested that the varibles are being populated with the correct values, strange.
I'll sleep on it and has a look at the register_globals see if that throws any light on it.
Posted by Chris_Isaac (Chris Isaac), 9 February 2004update: I've now installed the scripts on my local machine at home as well and it is coming up with the same problem.
I had a look at the global varibles on my local machine as well as the remote machine (where the scripts work correctly). There is an entry called varibles_order, which on my local machine is set to EGPCS, but on the remote machine is set to NO VALUE. Could this be it? I've had a quick look at the others, some others do differ but I think this is due to my local machine running Win XP and the remote running FreeBSD.
Would any other varibles have this effect on a script?
Also just noticed my local machine is running 2.0.48 and the remote is running 1.3.28
Thanks in advance.
Posted by admin (Graham Ellis), 9 February 2004Suggestion - try printing out the variables that are concerned with the tests in the problem area rather than just "I am here" messages. My conjecture is that at least one of your variables is not being collected from $_GET and so you're prone to server configuration; I couldn't see where $incode came from in the snippet of code you posted. The version number of Apache won't effect you so much as the version number of PHP.
The register_globals setting needs to be on before the variables_order has any effect, but do check $incode first as outlined above.
Posted by Chris_Isaac (Chris Isaac), 9 February 2004Thank you it was the register_globals, it was turned off, I turned it on and it works fine.
I did notice in the php.ini file that it says you should try to keep this feature turned off, for security. Obviously on my local macine for testing it doesn't matter, but if I did need/want to keep it turned off, how could I have got around it?
Posted by admin (Graham Ellis), 9 February 2004You should not rely on form / environment / cookie / server variables turning up in your code in variables with the same names as the form / environment / cookie / server field. Instead, you should always use $_GET $_POST $_REQUEST $_COOKIE $_ENV and $_SERVER as appropriate. You are using $_GET already for some variables, but clearly not consistently - otherwise changing the register_globals setting wouldn't have made any difference
Posted by Chris_Isaac (Chris Isaac), 9 February 2004What confuses me is I thought I was using $_GET, specially on the 2 varibles I was having trouble with:
$incode doesn't in the code you can see I admit, but $incode isn't causing a problem anyway.
Confused, but happy its working, thanks for your help
PH: 01225 708225 • FAX: 01225 793803 • EMAIL: email@example.com • WEB: http://www.wellho.net • SKYPE: wellho