hybridpunk Posted March 19, 2011 Share Posted March 19, 2011 Basically what I am trying to achieve is making sure any $page called originates from my server, but if no $page is defined, to include a default page I have set up. This is my code, and I cannot figure out what's wrong with it. <?php $path = 'pages/'; $extension = '.txt'; if ( preg_match("#^[a-z0-9_]+$#i",$page) ){ $filename = $path.$page.$extension; include($filename); } if (!$page) include 'pages/main.txt'; ?> An example URL I am using is www.mywebsite.com/index.php?$page=pages/tester What am I doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/231063-requiring-includes-to-come-from-server-side/ Share on other sites More sharing options...
Eyewash01 Posted March 19, 2011 Share Posted March 19, 2011 Brackets around the second occurence of include missing? Quote Link to comment https://forums.phpfreaks.com/topic/231063-requiring-includes-to-come-from-server-side/#findComment-1189474 Share on other sites More sharing options...
hybridpunk Posted March 19, 2011 Author Share Posted March 19, 2011 I have fixed that, and I am still getting the same result, it is always loading the main.txt instead of the pages i am requesting Quote Link to comment https://forums.phpfreaks.com/topic/231063-requiring-includes-to-come-from-server-side/#findComment-1189574 Share on other sites More sharing options...
PFMaBiSmAd Posted March 19, 2011 Share Posted March 19, 2011 Where in your code are you setting the $page variable at, from the $_GET['page'] value? Quote Link to comment https://forums.phpfreaks.com/topic/231063-requiring-includes-to-come-from-server-side/#findComment-1189577 Share on other sites More sharing options...
Pikachu2000 Posted March 19, 2011 Share Posted March 19, 2011 I don't see anywhere in that code where $page is defined. Quote Link to comment https://forums.phpfreaks.com/topic/231063-requiring-includes-to-come-from-server-side/#findComment-1189578 Share on other sites More sharing options...
hybridpunk Posted March 19, 2011 Author Share Posted March 19, 2011 I was assuming that the code would pull $page from the URL, I guess I assumed wrong? If so, what would I need to do to fix this? Quote Link to comment https://forums.phpfreaks.com/topic/231063-requiring-includes-to-come-from-server-side/#findComment-1189583 Share on other sites More sharing options...
Pikachu2000 Posted March 19, 2011 Share Posted March 19, 2011 That would only happen if register_globals = On in the php.ini file, which it definitely should not. You need to assign the value from the $_GET array to the variable you want to use. i.e. $page = $_GET['page'] or use $_GET['page'] directly. Quote Link to comment https://forums.phpfreaks.com/topic/231063-requiring-includes-to-come-from-server-side/#findComment-1189584 Share on other sites More sharing options...
hybridpunk Posted March 19, 2011 Author Share Posted March 19, 2011 Thank you very much, that fixed the problem. At first it wasn't working, then I realized that my urls were looking like index.php?page=pages/blah, after deleting pages/ from the url, everything worked fine. I greatly appreciate your help. Quote Link to comment https://forums.phpfreaks.com/topic/231063-requiring-includes-to-come-from-server-side/#findComment-1189589 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.