nepzap2 Posted October 27, 2009 Share Posted October 27, 2009 Does anyone know what where I can find information on the following. I have seen several website that use a single page that then has extensions that follow the actual page. Like "page.php?id=2" or "page.php?page=home" almost like information gets re-routed through a control page that then takes care of the look of that page depending on the page itself. Where can I learn more about this or is there a tutorial here that I can explore? Many Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/179226-i-need-some-help/ Share on other sites More sharing options...
MadTechie Posted October 27, 2009 Share Posted October 27, 2009 a simple example would be test.php?page=cpanel or test.php?page=profile switch($_GET['page']) { case "cpanel": include('cpanel.php'); break; case "profile": include('profile.php'); break; } Quote Link to comment https://forums.phpfreaks.com/topic/179226-i-need-some-help/#findComment-945587 Share on other sites More sharing options...
mrMarcus Posted October 27, 2009 Share Posted October 27, 2009 ^beat me to it .. i'm so slow; trying to keep it simple, this is a combination of a template-driven website using the $_GET superglobal for page referencing. you access the variable (string) from the URL via $_GET: <?php $page = $_GET['page']; //would make $page = 'home' as per your post ("page.php?page=home"); ?> you could then use a switch() statement to determine which page to display: <?php $safe_urls = array ('home', 'contact', 'blog'); //add more as needed / for security; if (in_array ($_GET['page'], $safe_urls)) { $page = htmlentities ($_GET['page']); } switch ($page) { case home: include 'homepage.php'; break; case contact: include 'contact.php'; break; case blog: include 'blog.php'; break; default: include 'homepage.php'; break; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/179226-i-need-some-help/#findComment-945591 Share on other sites More sharing options...
MadTechie Posted October 27, 2009 Share Posted October 27, 2009 As mrMarcus pointed out you can add security, but this is only needed if you use the value directly, ie include $_GET['page'].'.php'; which is insecure, a secure use would be <?php $safe_urls = array ('home', 'contact', 'blog'); //add more as needed / for security; if (in_array ($_GET['page'], $safe_urls)){ include $_GET['page'].'.php'; }else{ include 'index.php'; //default page } ?> Quote Link to comment https://forums.phpfreaks.com/topic/179226-i-need-some-help/#findComment-945609 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.