Guest groovejuice Posted February 7, 2006 Share Posted February 7, 2006 I'm using the following code to emulate a frame/iframe with php. It works as expected until I set register globals to off in htaccess. Then, none of the include pages load. I'm just teaching myself php, so forgive me if the answer is self-evident. <?php if (!isset($_GET['page'])) $page= 'bursaries'; switch($page) { case 'bursaries': include ('bursaries.htm');break; case 'board': include ('board.htm');break; case 'agm':include ('agm.htm');break; case 'contact':include ('contact.htm');break; } ?> Quote Link to comment Share on other sites More sharing options...
Guest groovejuice Posted February 8, 2006 Share Posted February 8, 2006 Anyone? Thanks. Quote Link to comment Share on other sites More sharing options...
Guest Posted February 9, 2006 Share Posted February 9, 2006 I'm using the following code to emulate a frame/iframe with php. It works as expected until I set register globals to off in htaccess. Then, none of the include pages load. I'm just teaching myself php, so forgive me if the answer is self-evident. <?php if (!isset($_GET['page'])) $page= 'bursaries'; switch($page) { case 'bursaries': include ('bursaries.htm');break; case 'board': include ('board.htm');break; case 'agm':include ('agm.htm');break; case 'contact':include ('contact.htm');break; } ?> I think I see the problem here. Your switch statement depends on the value of $page, when what you're actually looking for is $_GET['page']. Unless you set $page to $_GET['page'] they remain two completely separate variables. There are different ways to code this, but I usually set the values of the simple variables (e.g., $page) at the top of my script so that I don't get cross-eyed looking at them later. So what you need to do is to set $page to the value of $_GET['page']. For example: if (isset($_GET['page'])) $page = $_GET['page']; else $page= 'bursaries'; Now $page should be what you're expecting (the value sent in the URL or the default page). Quote Link to comment Share on other sites More sharing options...
Guest groovejuice Posted February 9, 2006 Share Posted February 9, 2006 Thanks Zap, I appreciate your help. I'll give it a shot. I'm curious as to why the original code works only with register globals on, though. Quote Link to comment Share on other sites More sharing options...
Guest Posted February 9, 2006 Share Posted February 9, 2006 Thanks Zap, I appreciate your help. I'll give it a shot. I'm curious as to why the original code works only with register globals on, though. Well that's the difference between register_globals on and off. When register_globals is on all of the variables that PHP finds in the URL, form posts, sessions, and cookies are "registered" (meaning they are automatically available globally using their simple name, e.g. $page). When register_globals is off variables found in those sources are only available when you specify their source (_GET from the URL, _POST from forms, _COOKIE from cookies, _SESSION from the session, and _REQUEST from any of those places). So this just means that when you want to use a variable from one of those sources when register_globals is off you need to look for it where you expect to find it (in one of the predefined arrays above). This keeps hackers from injecting global variables into your script in ways that you don't expect (usually via the query string in the URL, but also in form posts, etc.), so it is far more secure. All that coders need to do in order to adjust to this change is to take into account where these variables come from (see example above). You can find out more about register_globals here. Quote Link to comment Share on other sites More sharing options...
Guest groovejuice Posted February 9, 2006 Share Posted February 9, 2006 Thanks again, not only for your assistance, but for the patient and informative response. I'm finally getting this stuff..... Quote Link to comment Share on other sites More sharing options...
Guest Posted February 9, 2006 Share Posted February 9, 2006 Thanks again, not only for your assistance, but for the patient and informative response. I'm finally getting this stuff..... You're very welcome. 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.