Jump to content


This topic is now archived and is closed to further replies.


get index.php to load other pages

get index.php to load other pages  

  1. 1. get index.php to load other pages

    • a
    • b

Recommended Posts

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.php

the header has the main menu.

the main menu has member login which will call the mainlogin.php

now when i click on member login it should call mainlogin.php

i can add the link to it as /mainlogin.php

but i

i want the mainlogin to be read dynamically by doing something like this

index.php code.


$p = $_GET['page'];

if (strpos($p,"..")) {
    die("Bad page request");

if (!$p) $p = "index";
if (!file_exists($content_file)) {
    header("Location: {$_SERVER["PHP_SELF"]}");

$title = ($p) ? "$p - My Site!" : "Main page - My Site!";

how will this code read my mainlogin.php file when i click on member login.
i want the link dynamic in my menu.

Share this post

Link to post
Share on other sites
<a href="index.php?p=mainlogin">Login</a>

That should do the job if i'm interprited what you wrote correctly :)


Share this post

Link to post
Share on other sites
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:
case 'news':
include 'news.php';
case 'login':
include 'login.php';
case 'downloads':
include 'downloads.php';
include main.php;
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=xxxx

So for your case it would be index.php?option=login
The 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!

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.