Php Question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Jonny462
Forum Newbie
Posts: 3
Joined: Mon Apr 10, 2006 9:46 am

Php Question

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

viewtopic.php?t=37950 may be of use/help.
Jonny462
Forum Newbie
Posts: 3
Joined: Mon Apr 10, 2006 9:46 am

Post 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
jonathant
Forum Commoner
Posts: 32
Joined: Sat Jan 07, 2006 3:13 pm

Post 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...
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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?
Jonny462
Forum Newbie
Posts: 3
Joined: Mon Apr 10, 2006 9:46 am

Post by Jonny462 »

jonathant,

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

thanks alot
Post Reply