Jump to content

get index.php to load other pages


truenitin

get index.php to load other pages  

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

    • a
      0
    • b
      0


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.

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

Link to comment
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:
[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=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!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.