Jump to content


Photo

get index.php to load other pages


  • Please log in to reply
2 replies to this topic

Poll: get index.php to load other pages (0 member(s) have cast votes)

get index.php to load other pages

  1. a (0 votes [0.00%])

    Percentage of vote: 0.00%

  2. b (0 votes [0.00%])

    Percentage of vote: 0.00%

Vote Guests cannot vote

#1 truenitin

truenitin
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 04 July 2006 - 01:22 PM

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.



#2 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 04 July 2006 - 01:48 PM

<a href="index.php?p=mainlogin">Login</a>


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

Regards
Liam
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#3 Chips

Chips
  • Members
  • PipPipPip
  • Advanced Member
  • 68 posts

Posted 04 July 2006 - 01:58 PM

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:
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;
}
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!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users