php can link the include file to another include file?

Hello, did anyone know how to solve this problem?

how can i give the name of B.php ? <?php include('b.php') ?>

Then it allow me in A.php using can direct set the page display in B.php?

Please help me thank a lots ya!!~

You may see the image here for easy to understand : http://ols.my/ask-help.jpg


Usually done with some variation of this:

Menu:

<a href="/index.php?page=home">Home</a> <a href="/index.php?page=about">About</a> <a href="/index.php?page=contact">Contact</a>

index.php
[php]<?php

$page = isset($_GET[‘page’]) ? $_GET[‘page’] : ‘home’;

switch ($page) {
case ‘home’:
case ‘about’:
case ‘contact’:
// Inside this switch/case we know $page is a valid value so it’s safe to use it in an include
require ‘pages/’ . $page . ‘.php’;
break;
default:
// if it’s some other value, it has to be a non-valid page
require ‘pages/404.php’;
break;
}[/php]

Then you can optionally use apaches mod rewrite module to rewrite the links to a prettier format, ie the user sees “yourpage.com/about.html” while the server reads it as “yourpage.com/index.php?page=about

I had to give karma for that is a neat answer. :slight_smile:

thanks jimL !!

But i am not that pro on it…
coz i am web designer, not that pro in php code, actually i didnt learn php before, just know how to change some of the code.

Sample, in this page:
http://ols.my/products.php

i got 2 php included file.

<?php include('nav.php') ?>
<?php include('content.php?page=content') ?>

how to link the following code in content part?
Paint Brush

Nav code are here:
http://ols.my/nav.php

can you help again, using my code to add in?

From products.php you link to

brush.php?page=content

I would change this link to

products.php?product=brushes

then at the top of products.php
[php] <?php

$requestedProduct = isset($_GET[‘product’]) ? $_GET[‘product’] : ‘list’; //or whatever you called the first content

switch ($requestedProduct) {
case ‘list’:
case ‘brushes’:
case ‘socket-chrome’:
case ‘socket-impact’:
case ‘socket-set’:
// Inside this switch/case we know $requestedProduct is a valid value so it’s safe to use it in an include
$productPage = ‘products/’ . $requestedProduct . ‘.php’;
break;
default:
// if it’s some other value, it has to be a non-valid page
$productPage = ‘pages/404.php’;
break;
}[/php]

And further down in products.php

[php]

<?php include('nav.php') ?>
<?php include($productPage) ?>[/php]

[member=71845]JimL[/member] , That is not really an optimum way to go about it. If you have a thousand pages you will have a thousand cases and will have to maintain it when more pages are added or deleted.

An array of DIS-allowed pages would be better. (IE: header.php, footer.php, menu.php, navbar.php, etc…)

OP, download the PDO bumpstart database from my signature and you will see a clean dynamic way to go about this. It is about as close to a router in MVC as you can get without going MVC. It is exactly what you are looking for and is already in PDO & Bootstrap.

index.php
[php]include_once(’./includes/display_pages.php’);

//----------------------------------------------------------------------------------------
// Include Page Header
//----------------------------------------------------------------------------------------

include_once(’./includes/header.php’);
?>

<?php include_once('./includes/navbar.php'); ?>
<?php include_once('./includes/menu.php'); ?>
<?php include_once("$include"); ?>
  </div><!-- /.row -->
</div> <!-- /.container -->
<? include_once('./includes/footer.php'); ?>[/php]

display_pages.php
[php]<?php
/*

  • This file: display_pages.php
  • Acts as a Router to display pages
  • Restricts access to certain files

*/

//------------------------------------------------------------------------
// Restrict access to these files
//------------------------------------------------------------------------

// Specify some disallowed paths
$restricted_files = array(
‘header’,
‘footer’,
‘navbar’,
‘menu’
);

//----------------------------------------------------------------------------------------
// Display Pages
//----------------------------------------------------------------------------------------

if (isset($_GET[‘p’]))
{

$page = basename($_GET['p']);

// If it's not a disallowed file, and if the file exists
if (!in_array($page, $restricted_files) && file_exists("./includes/$page.php"))
    {
    $include = "./includes/$page.php";
    }
else
    {
    // Page Not Found
    $include = './includes/404.php';
    }
}

else
{
$include = ‘./includes/default.php’;
}
?>[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service