Jump to content

getting other page to display on index.php


irkevin

Recommended Posts

Hi, i want to do something but i don't really know how to achieve this

 

I have index.php and all want all page to display on index.php.. Supposed i have

 

home | music | stuffs | aboutus

 

i would like it to display on index.php. Just like the url would be

 

index.php?page=home

index.php?page=music

index.php?page=stuffs

index.php?page=aboutus

 

I know that switch , case and break have something to do with it but know how to apply it !

 

Can someone give me a brief example please?

just include one page for this .. and do it with a  if condition...

 

it will be more easier for you....

 

i have one example with me... and i think it will be more difficult to you to understand...

 

if you really want it i will send it to you.....

You'll want to use $_GET['page'] to grab the page url variable. You'll then want to setup an array of all the pages visitors are allowed access to, eg

$my_pages = array('home', 'music', 'stuffs', 'aboutus');

 

Then you'd use in_array function within an if statement to check if the value of $_GET['page'] is stored in the $my_pages array. If its you'd then use $_GET['page'] in an include.

 

Example code:

// check that $_GET['page'] is present, if its not we'll setup a default page
if(isset($_GET['page'])) && !empty($_GET['page']))
{
    $requested_page = strtolower($_GET['page']);
}
else // $_GET['page'] not found or is empty, so we'll setup a default page to be requested 
{
    $requested_page = 'home';
}

// setup an array of all your sites pages
$my_pages = array('home', 'music', 'stuffs', 'aboutus');

$requested_page = strtolower($_GET['page']);

// make sue the request page is in $my_Pages array
if(in_array($requested_page, $my_pages))
{
    // the requested page will be included from a folder called my_pages in your websites root folder.
    // I assume the files to be included are html files
    include $_SERVER['DOCUMENT_ROOT'] . '/my_pages/' . $requested_page . 'html';
}
else
{
    // requested_page not found
    die( 'The requested page (' . $requested_page ') was not found!' );
}

wouldn't this work also? it's an example i found on this forum

 

<a href="?page='one'>LINK ONE</a>
<a href="?page='two'>LINK TWO</a>
<a href="?page='three'>LINK THREE</a>
<?php

  if (isset($_GET['page'])) {
    switch ($_GET['page']) {
      case 'one':
        echo "this is one";
        break;
      case 'two':
        echo "this is two";
        break;
      case 'three':
        echo "this is three";
        break;
    }
  }

?>

 

Hoe do i make it dispkay the homepage as a default! See what i mean?

 

Thanks in advance

Which mean it could be like this

 

<?php

 

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

    switch ($_GET['page']) {

      case 'one':

        echo "this is one";

        break;

      case 'two':

        echo "this is two";

        break;

      case 'three':

        echo "this is three";

        break;

 

    default:

    echo "the code for the homepage goes there???";

    }

  }

 

?>

i have those codes

<a href="indexa.php?">Home</a>
<a href="indexa.php?page=add">Add Anime</a>
<a href="indexa.php?page=edit">Edit Anime</a>

<?php
  $page = $_GET['page'];
  if (isset($page)) {
    switch ($page) {
      case 'add':
        echo "Testing the add page";
        break;
      case 'edit':
        echo "Testing the edit page";
        break;
      default:
        echo "This is the home page where you'll have info";
    }
  }

?>

I want to have the indexa.php page to be the default page and show this message "This is the home page where you'll have info"

How do i do that? 

thanks




 

<a href="indexa.php?">Home</a>
<a href="indexa.php?page=add">Add Anime</a>
<a href="indexa.php?page=edit">Edit Anime</a>

<?php
  if (isset($_GET['page'])) {
    switch ($_GET['page']) {
      case 'add':
        echo "Testing the add page";
        break;
      case 'edit':
        echo "Testing the edit page";
        break;
      default:
        echo "This is the home page where you'll have info";
    }
  } else {
    echo "This is the home page where you'll have info";
  }

?>

or what i did is just use the if statement without the switch statements so...

<?
if($_GET['page']==home){
//home page code goes here
}
if($_GET['page']==music){
//music page code goes here
}
if($_GET['page']==stuffs){
//stuffs page code goes here
}
if($_GET['page']==aboutus){
//about us page info goes here
}
?>

 

 

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.