sfboy Posted May 2, 2006 Report Share Posted May 2, 2006 This code is currently here <?php switch($op){ case 'h': echo "hello"; break; case 'b': echo "bye"; break; default: echo "no op switch detected"; break; } ?> now correct me if I'm wrong but whenever I go to http://mtbstatic.com/sc/ebay/test4.php?op=bthe output should be byeand http://mtbstatic.com/sc/ebay/test4.php?op=hthe output should be hellobut the output is always "no op switch detected", this has never happened on any other host or am I just overlooking something really obvious in the code.http://mtbstatic.com/sc/ebay/test4.php' target="_blank"> Quote Link to comment Share on other sites More sharing options...
Extreme_biker0 Posted May 2, 2006 Report Share Posted May 2, 2006 (edited) You need to grab the 'get' data from the url and put it in the $op variable mate.Somat like$op = $_GET['op'];but i'm rusty on the actual code so i hope you get what I mean. Edited May 2, 2006 by Extreme_biker0 Quote Link to comment Share on other sites More sharing options...
sfboy Posted May 2, 2006 Author Report Share Posted May 2, 2006 Legend, although I've never had to do this with any other host, bizzarre. Quote Link to comment Share on other sites More sharing options...
Extreme_biker0 Posted May 2, 2006 Report Share Posted May 2, 2006 I've never known url get data put straight into variables with the same name before how strange Glad to help. Quote Link to comment Share on other sites More sharing options...
sfboy Posted May 2, 2006 Author Report Share Posted May 2, 2006 Yeah, plus I never used to get data from forms, as long they had the same name tag as the variable. Now I need to use$var = $_POST[$var]what an arse! I guess it supposed to increase security but it means I need to modify all my pissing code. Quote Link to comment Share on other sites More sharing options...
tomturd Posted May 2, 2006 Report Share Posted May 2, 2006 A more up to date way of doing it is to use $mode = $HTTP_GET_VARS['mode'];[/code]You could just replace the variable with $HTTP_GET_VARS['mode'] directly, without assigning it to a variable at the top. Thats a bit messy though.Always been done that way as far as I remember Quote Link to comment Share on other sites More sharing options...
Simon Posted May 3, 2006 Report Share Posted May 3, 2006 For future reference, to use $op when calling from a url with ?foo=bar is called a global variable.You should never ever be able to do this. Most decent hosts have globals turned off, as its a super high security risk. I wont explain how, but trust me, if a host has globals turned on, i would consider changing just because of that fact.And as far as i know, $_GET is still the fore runner over $HTTP_GET_VARS. I use $_GET, as does everyone else i know, and all the code i see uses $_GET. Mainly because coders, by nature, are highly lazy, and $_GET is a lot quicker to type then $HTTP_GET_VARS. PHP 6 will be phasing out globals, and be disabling them by default, so i would try to avoid using them at all costs. Quote Link to comment Share on other sites More sharing options...
sfboy Posted May 3, 2006 Author Report Share Posted May 3, 2006 (edited) A more up to date way of doing it is to use $mode = $HTTP_GET_VARS['mode']; You could just replace the variable with $HTTP_GET_VARS['mode'] directly, without assigning it to a variable at the top. Thats a bit messy though.Always been done that way as far as I remember For future reference, to use $op when calling from a url with ?foo=bar is called a global variable.You should never ever be able to do this. Most decent hosts have globals turned off, as its a super high security risk. I wont explain how, but trust me, if a host has globals turned on, i would consider changing just because of that fact.And as far as i know, $_GET is still the fore runner over $HTTP_GET_VARS. I use $_GET, as does everyone else i know, and all the code i see uses $_GET. Mainly because coders, by nature, are highly lazy, and $_GET is a lot quicker to type then $HTTP_GET_VARS. PHP 6 will be phasing out globals, and be disabling them by default, so i would try to avoid using them at all costs. Actually, $_GET, $_POST, $_COOKIE, $_SERVER, $_ENV and $_SESSION variables deprecate the old $HTTP_*_VARS arrays and can be used regardless of the scope. There is no need to import them using the global statement within functions.EDIT: So that's why globals should be turned off. Edited May 3, 2006 by sfboy Quote Link to comment 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.