Jump to content

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


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]

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.