truenitin Posted July 4, 2006 Share Posted July 4, 2006 it is something like this i want the index page as the main page i want the header and footer to be included in all the pages.now i have a login file mainlogin.phpthe header has the main menu.the main menu has member login which will call the mainlogin.phpnow when i click on member login it should call mainlogin.php i can add the link to it as /mainlogin.phpbut ii want the mainlogin to be read dynamically by doing something like thisindex.php code.<?php$p = $_GET['page']; if (strpos($p,"..")) { die("Bad page request");}if (!$p) $p = "index";$content_file=$_SERVER["DOCUMENT_ROOT"]."/".$p.".php";if (!file_exists($content_file)) { header("Location: {$_SERVER["PHP_SELF"]}"); exit();}$title = ($p) ? "$p - My Site!" : "Main page - My Site!";include("header.php");include($content_file);include("footer.php");?>how will this code read my mainlogin.php file when i click on member login.i want the link dynamic in my menu. Quote Link to comment https://forums.phpfreaks.com/topic/13636-get-indexphp-to-load-other-pages/ Share on other sites More sharing options...
shocker-z Posted July 4, 2006 Share Posted July 4, 2006 <a href="index.php?p=mainlogin">Login</a>That should do the job if i'm interprited what you wrote correctly :)RegardsLiam Quote Link to comment https://forums.phpfreaks.com/topic/13636-get-indexphp-to-load-other-pages/#findComment-52877 Share on other sites More sharing options...
Chips Posted July 4, 2006 Share Posted July 4, 2006 I had an index.php file, which also includes a header, if logged in (user is logged in that is) then the main page is divided into two, with the menu displayed to the left for the users links, like account etc - which is just an include 'logged.php'; and content.php included for the rest of the page.Footer included beneath them.content.php has a switch statement - kind of like:[code]switch($_REQUEST['option']){case 'news': include 'news.php'; break;case 'login': include 'login.php'; break;case 'downloads': include 'downloads.php'; break;default: include main.php; break;}[/code]Well, to be strictly honest, it's actually functions not includes, and each function performs a series of actions - including just outputting html code, or including other files etc. There are error checks on whether its a string etc being passed, and also an overall error check on index.php which gets the url, explodes it around the ? and checks for things like SELECT, UNION, JOIN, ", ', ;, etc.Each "page" that gets included can check for other things, such as $_GET['id'] for the news - as in the news id if they select a news item to view in full.Since it all goes through the index.php (as everything is included through it), all my links are index.php?option=xxxx&id=xxxxSo for your case it would be index.php?option=loginThe login.php can have a form on it, or do error checking on processed things (ie you can submit back to index.php?option=login, and check to see whether your post variables are set with the correct values etc, and then login - otherwise display a form. Keeps the index.php small and neat, and everything else is fairly "independant" of the page - so changing login methods requires just swapping a file about, and not surfing through TONS of index.php code! Quote Link to comment https://forums.phpfreaks.com/topic/13636-get-indexphp-to-load-other-pages/#findComment-52880 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.