Page 1 of 1

Php Question

Posted: Mon Apr 10, 2006 9:58 am
by Jonny462
Im looking for a way to show something on a page based on its url.

The way I setup my pages I have my template in 2 pages (header.php, footer.php) and use include on the top and bottom of new pages and insert the page in the middle.. If you understand that. I want to be able to show a small dropdown menu at the bottom based on what page the person is on. I want to be able to put this on the main template file so I dont have to copy the dropdown to every page and to let me update it easier.

Example: If Im on the main page and click on tutorials it would show a dropdown showing different tutorial headings for easier navigation.

Ive been trying this for a while with different codes but Im new to php so most is guessing or changing other code. ive never got just what i wanted.

If anyone could help it would be great.


Thanks,
Jonny

Posted: Mon Apr 10, 2006 10:01 am
by feyd
viewtopic.php?t=37950 may be of use/help.

Posted: Mon Apr 10, 2006 10:49 am
by Jonny462
ok from what I read I came up with this:

Code: Select all

<?
function geturl() 
{ 
  $ports = array('https' => 443, 'http' => 80); 
  $prefix = (empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == "off" ? 'http' : 'https'); 
  $url = $prefix; 
  $url .= '://'; 
  $url .= $_SERVER['HTTP_HOST']; 
  $url .= $_SERVER['SERVER_PORT'] != $ports[$prefix] ? ':' . $_SERVER['SERVER_PORT'] : '';
  $url .= $_SERVER['PHP_SELF']; 
  $url .= (isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] != "" ? "?".$_SERVER['QUERY_STRING'] : "");
  return $url; 
} 

 if ($url == http://name.com/) { ?>
<select name="name"><option selected="selected">Name</option>
<option selected="selected">Name2</option>
<?
}
?>
Im gonna be in work for a while so can anyone tell me if it would work or if theres anything wrong with it.

Thanks,
Jonny

Posted: Mon Apr 10, 2006 6:49 pm
by jonathant
If you are including header and footer at the top and bottom of each page, then your scripts look like this right?

Code: Select all

include("header.php");
/* script for stuff on page */
include("footer.php");
If that is the case, then you could just do something like:

Code: Select all

include("header.php");
/* script for stuff on page */

$current_script="home"; /* or whatever the name of the page is */
include("footer.php");
Then in footer.php something like:

Code: Select all

if ($current_script="home")  /* switch would be better, but you get the idea */
{
     /* populate array for drop down or whatever */
}
/* rest of footer code */
I think that would work...

Posted: Mon Apr 10, 2006 8:06 pm
by RobertGonzalez
How much of the current page name do you need? I think you can use basename() to get the name of the current page. Set that page name to a var then use that var for comparison.

In the projects I have done using page names (which have been quite a few) I have used the current page name and directory name to decide which navigation to show users. That way they will see only those pages that are within the directory they in. Is this what you are after?

Posted: Tue Apr 11, 2006 6:26 am
by Jonny462
jonathant,

thats a pretty good idea.. that I Probably wouldn't of thought of :D

thanks alot