Jump to content

home as default, and linking in other pages...


Exact

Recommended Posts

hey guys,

 

here is probably the simplest question you have ever seen.... sorry, im a newbie

 

i have a index.php files that includes: footer.php header.php menu.php and home.php.

 

where i have

<?php include("home.php"); ?>

, i want to be able to go to mysite.com.au/index.php?page=about etc and where home.php is i want these to appear when called about.php, contact.php, new.php, products.php.

 

but i also want home.php to be the default page so when you go to mysite.com it appears...

Look into the switch statement:

 

switch ($_GET['page']) {
     default:
     case 'home':
                include('home.php');
     break;
     case 'about':
                include('about.php'); 
     break;
}

 

Hope that helps ya.

You can use glob to generate a dynamic list via an array and loop through it and test/include that if you would like.

 

$files = glob('*.php');
if (isset($_GET['page'])) {
    foreach ($files as $file) {
          if (strtolower($_GET['page']) . ".php" == $file) {
                  include($file);
          }
   }
}

 

Un-tested but it is a rough example of what you can do.

hehe. sorry. the last code

$files = glob('*.php');if (isset($_GET['page'])) {    foreach ($files as $file) {          if (strtolower($_GET['page']) . ".php" == $file) {                  include($file);          }   }}

 

i cant get it to display home.php as default. and when you go to /index.php?page=about    it is not displaying about.php

 

so if i do this it comes up blank. with no page and no error:

 

<?php $files = glob('*.php'); if (isset($_GET['page']))  
{ else { include 'home.php'; }  foreach ($files as $file) {          
if (strtolower($_GET['page']) . ".php" == $file) {                  include($file);          }   }}
?>

 

Also yes they are all in the same folder

sorry dude, should've been more specific:

 

$files = glob('*.php');

if (isset($_GET['page'])) {

    foreach ($files as $file) {

          if (strtolower($_GET['page']) . ".php" == $file) {

                  include($file);

          }

  }

}

else

{ include 'index.php'; }

ha thnks... just posting this.... this worked....

 

thanks heaps for your help....  :D

 

ok i got it.... by using this:

[code]		<?php $files = glob('*.php'); if (isset($_GET['page'])) 
{   foreach ($files as $file) {          if (strtolower($_GET['page']) . ".php" == $file) {                  include($file);          }   }} 
else { include 'home.php'; }
?>

 

Thanks heaps for your help!  ;)[/code]

Archived

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

×
×
  • 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.