Cultureshock Posted March 1, 2010 Share Posted March 1, 2010 I have a config.php at the top of both pages that contains (amongst other code) <?php $boxselected=$_GET['b']; ?> Now in the files I use $boxselected for a few different purposes but I never change it. (ie it always stays the same info passed in the address bar as ?b=example) However, only in one of the files does $boxselected worked. HOWEVER other lines of config.php ARE working in BOTH pages. Is there any code that would disable $_GET that might be interfering? The page on which $boxselected does NOT work uses a function contained in config.php. But I don't see why that would affect $_GET. And I've checked spelling/ typos so please don't suggest that Quote Link to comment https://forums.phpfreaks.com/topic/193840-php-_get-working-in-one-page-and-not-another/ Share on other sites More sharing options...
PFMaBiSmAd Posted March 1, 2010 Share Posted March 1, 2010 What value does $boxselected end up with? You likely have some code on that page that is overwriting $boxselected, such as - if($boxselected = something) rather than if($boxselected == something) The first example sets $boxselected to something and then tests the resulting value. The second example tests if $boxselected is equal to something. Quote Link to comment https://forums.phpfreaks.com/topic/193840-php-_get-working-in-one-page-and-not-another/#findComment-1020173 Share on other sites More sharing options...
Cultureshock Posted March 2, 2010 Author Share Posted March 2, 2010 It's not currently used in any if statements. Thanks though. I looked around a second time to make sure I wasn't writing over it or w/e. Quote Link to comment https://forums.phpfreaks.com/topic/193840-php-_get-working-in-one-page-and-not-another/#findComment-1020182 Share on other sites More sharing options...
PFMaBiSmAd Posted March 2, 2010 Share Posted March 2, 2010 What does a phpinfo() statement show for the register_globals setting? register_globals being on is about the only reason variables will get overwritten when there is no actual code doing it. Quote Link to comment https://forums.phpfreaks.com/topic/193840-php-_get-working-in-one-page-and-not-another/#findComment-1020196 Share on other sites More sharing options...
Cultureshock Posted March 2, 2010 Author Share Posted March 2, 2010 It works in another page, though. Note: When echoed, it's *NOT* blank. Quote Link to comment https://forums.phpfreaks.com/topic/193840-php-_get-working-in-one-page-and-not-another/#findComment-1020218 Share on other sites More sharing options...
Cultureshock Posted March 2, 2010 Author Share Posted March 2, 2010 ^ But it IS blank when used in the function I made, even though $boxselected is defined before the function EDIT: I redefined $boxselected inside the function and it works. Is there any other way to do it without redefining the same thing twice? Quote Link to comment https://forums.phpfreaks.com/topic/193840-php-_get-working-in-one-page-and-not-another/#findComment-1020223 Share on other sites More sharing options...
khr2003 Posted March 2, 2010 Share Posted March 2, 2010 what do you mean by However, only in one of the files does $boxselected worked. HOWEVER other lines of config.php ARE working in BOTH pages. Do you send the values of config.php to $_GET array? It is always a good practice to print this line: echo nl2br(print_r($_GET,1)); Where you can see the whole array $_GET and check its keys and values. Is there any other way to do it without redefining the same thing twice? just add the beginning of the function "global $boxselected;" or make "$boxselected" one of the parameters passed to the function. Quote Link to comment https://forums.phpfreaks.com/topic/193840-php-_get-working-in-one-page-and-not-another/#findComment-1020251 Share on other sites More sharing options...
PFMaBiSmAd Posted March 2, 2010 Share Posted March 2, 2010 Please don't recommend using the global keyword to being values into a function. Could you imagine what a mess php would be like as a programming language if all of the built in functions did that and you had to keep track of which values were used by which function because they would all need to be uniquely named so that you could use more than a few functions without conflict? Only bring values into functions by passing them in as parameters so that you maintain the general purpose nature and encapsulation that functions are supposed to provide. Quote Link to comment https://forums.phpfreaks.com/topic/193840-php-_get-working-in-one-page-and-not-another/#findComment-1020363 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.