Page 1 of 1

PHP where you are links help

Posted: Sat Jan 17, 2009 8:21 am
by tomsace
Hey, I use the php command on my website to get multiple pages out of one php file.
The code I am using is similar to this:

Code: Select all

 
<?php
 
$cmd = $_GET['cmd'];
if ($cmd=="") { $cmd = "page1.php"; } 
 
@include('header.php');
 
switch($cmd)
{
 
case "page1":
@include('page1.php');
break;
 
case "page2":
@include('page2.php');
break;
 
case "page3":
@include('page3.php');
break;
 
}
@include('footer.php');
 
?> 
 
This is so I can just type the content of each page in page1.php page2.php and page3.php. But what I need help with is also adding in the header file where the user is on each page.

For example: Home > Products > Shoes > Nike etc...

How can I edit my script so that I can also change the menu on each page?

Thanks in advance.

Re: PHP where you are links help

Posted: Sat Jan 17, 2009 9:54 am
by watson516
Providing the menu doesn't come before the switch statement you can use a session to keep track of the current page.

Code: Select all

<?php
session_start();
//Put whatever code you want here
switch($cmd)
{
      case "page1":
             $_SESSION['page']="page1";
             include('page1.php');
             break;
      case "page2":
             $_SESSION['page']="page2";
             //Rest of code
}
 
If the menu comes before this switch statement, ie in the header.php file, this won't work because the session variable gets set after the menu is rendered. In that case, you could put a switch into your menu code to check the value of $_GET['cmd'] and change it right inside the menu.

Re: PHP where you are links help

Posted: Sat Jan 17, 2009 9:55 am
by Burrito
please use PHP tags next time you post code in the forums.

in your header.php file:

Code: Select all

 
$breadcrumbs->show();
 
in your switch() (would need to be done above your call to header.php)

Code: Select all

 
$breadcrumbs->set($_GET['cmd']);
 

Re: PHP where you are links help

Posted: Sat Jan 17, 2009 5:12 pm
by tomsace
Thanks alot everyone. Got this working perfectly.