Results 1 to 15 of 15

Thread: Dynamic page - title?

  1. #1
    Join Date
    Nov 2004

    Question Dynamic page - title?


    I’m making a website system that will automatically include the header, content and footer. This is my code:
    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Home Page</title>
    <link href="design/styles/main.css" rel="stylesheet" type="text/css">
    <?php require("design/includes/header.htm"); ?>

    = array( "default""missing""help""website design" ); 

    $page = isset( $HTTP_GET_VARS['page'] ) ? strtolower$HTTP_GET_VARS['page']) : 'default'

    $check = @include($file); 

    if (
    in_array($page$pagesList) ) { 

    $page.'.php' ); 

    elseif (!


    <?php require("design/includes/footer.htm"); ?>
    I have a problem with the page titles, I have thought about using “<title>Site - <? echo $_GET['page']; ?></title>” and to use the URL “?page=Website%20Design” but I’d rather not. What can I do?

  2. #2
    Join Date
    Nov 2004
    How are you getting to the page? If it's one page that a user clicks a link (thus the URL '?page=Web%20Design') then you could instead use a cookie, or a session. That way it gets rid of the need to pass the variable through the URL.

    If I'm completely misunderstanding your question, I blame Warcraft and the obsession that requires me to stay up late.

    "I killed the world once! You can too, if you try hard!"
    --Lews Therin,
    Robert Jordan's "The Wheel of Time"

  3. #3
    Join Date
    Nov 2004
    Hehe, yea I don’t mind about the variables in the URL.

    I want to change the actual page title.

  4. #4
    Join Date
    Nov 2004
    Have you tried:
    PHP Code:
    <title>Site - <? echo urldecode($_GET['page']); ?></title>
    "I killed the world once! You can too, if you try hard!"
    --Lews Therin,
    Robert Jordan's "The Wheel of Time"

  5. #5
    Join Date
    Nov 2004
    What will that do, just get the ?page= variable dispalyed as the page title?

  6. #6
    Join Date
    Nov 2004
    I'm not sure what you're wanting to do....consider this example to explain what that line of code does:

    the url is: http://www.somedomain.com/index.php?page=Web%20Design

    when you: echo urldecode($_GET[page]);, in the title tags, it displays Web Design, and not Web%20Design

    If that's not what you're asking, I will throw a right back at you
    "I killed the world once! You can too, if you try hard!"
    --Lews Therin,
    Robert Jordan's "The Wheel of Time"

  7. #7
    Join Date
    Nov 2004
    Yea, I’ve already tried that and I know it displays Website Design.

    What I want to know is how I can add an extra array so when “domain.com/index.php?page=website_design” is requested it can display anything like “Website Design Page” and so on for all the pages.

  8. #8
    Join Date
    Jan 2003
    Windsor, UK
    What I use for the sites I manage is the following:

    I've simiplified out all the meta, encoding info, doc types, etc.. I have it setup to display a different image on differents page and I've removed that aswel for the example so... anyway....

    3 Files -
    head.inc.php - containing all the header information
    foot.inc.php - containg all the footer information
    pagename.php - the contentm plus the calls to include the head and foot files.

    In the head.inc.php file I have the following:
    PHP Code:
    if ($pgname == "") {
    $pgname "Default Page Title";
    $title $pgname .  " - BA Silver Wing Sailing Club ";
    <title><?php print($title); ?></title>
    And then in pagename.php I have
    PHP Code:
    $pgname = "Join Us"; 
    <p>Content Here</p>
    <? include("foot.inc.php"); ?>
    I'm sure you can follow what it's doing, setting the variable when the page is requested, and then passing it on to the header file which then adds - BA Silver Wing Sailing Club to the end of it, so that's on every page, and you can change the first bit for each page by changing the $pgname string, so you end up with titles like the following for example:
    Welcome - BA Silver Wing Sailing Club
    Join Us - BA Silver Wing Sailing Club
    Contact - BA Silver Wing Sailing Club

    If a title isnt set, it uses the 'Default Title' instead.
    Which you can have as an echo, like I put in above, or you can use like I do on some of my sites: (date($format)); which sets the date.

    You can add all sort of extra things to it, like I also have
    PHP Code:
    if ($imgname == "runrandom") { include("s/ranimg.php"); }
    else { 
    $imgloc "images/".$imgname; } 
    in the header file, and
    PHP Code:
    $imgname "history.jpg";
    $imgalt "WASC - 1994"
    in the page file.

    What this does, it allows me to have a different image at the top of every page, by setting the name of the image in the image directory, history.jpg, main.gif, contact.jpg, location.gif, etc... But if I set $imgname string as the text - runrandom then it runs the random image script and displays a random header image on that page.

    I hope some of that makes some sort of sense.

    Last edited by GavinPearce; 12-04-2004 at 12:53 PM.
    Have I really been coming here for 6 years? You would have thought I would have learnt something by now!

  9. #9
    Join Date
    Aug 2003
    Oslo, Norway
    If you don't have a lot of pages you want to administer the titles of, you could just delete the <title> tag on your index.php page and instead put it on your included pages. Index.php will use that <title> tag. Like this:

    index.php has no <title> tag
    test.php has a <title> tag ( <title>Test</title> )
    beer.php has a <title> tag ( <title>Beer</title> )

    index.php?page=test will have the title Test
    index.php?page=beer will have the title Beer

    But, if you have a few hundred pages to maintain, gavinnet's suggestion makes perfect sense.


  10. #10
    Join Date
    Nov 2004
    I'm not sure how well this would work (but in my mind's eye, it will work, dammit!!)

    have an array:

    PHP Code:
    $array = array("Title 1 Page""Title 2 Page""Title 3 Page"); 
    Then, the URL would be www.somedomain.com/index.php?page=1

    The the title would be:

    PHP Code:
    <TITLE><? echo $array[$page]; ?></TITLE>
    Of course, this would make the title 'Title 2 Page' being the nature of arrays and starting at 0.

    Is this what you wanted?

    "I killed the world once! You can too, if you try hard!"
    --Lews Therin,
    Robert Jordan's "The Wheel of Time"

  11. #11
    Join Date
    Aug 2004
    I have done something like this:
    PHP Code:
    ### functions.txt ###
    function header($title)
      echo <<<EOD
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html lang='en'><head><title>
    <META HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=ISO-8859-1'>
    <LINK REL=stylesheet HREF='style.css'>

    PHP Code:
    ### some_page.php ###
    include "functions.txt";
    header("This Page's Title");
    <h1>This Page's Heading</h1>
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
    tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
    quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
    consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
    dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident,
    sunt in culpa qui officia deserunt mollit anim id est laborum</p>
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  12. #12
    Join Date
    Jan 2003
    Windsor, UK
    Something I forgot to add is that I tend to use head.inc.php instead of just ending it with the .inc and then I echo it out.

    This doesn't really achieve anything except it stops you viewing the contents of head.inc.php direct, which does nothing really except people can't find out what info is teh page info and what info is the header info.

    Stupid I know but just seems to me to be better than head.inc

    lol I'll shut up now.
    Have I really been coming here for 6 years? You would have thought I would have learnt something by now!

  13. #13
    Join Date
    Nov 2004
    Hi! A bit of a delay in my response!

    Thanks for your suggestions, but I decided not to use the variable URL (?page=) instead I’m using separate PHP pages which include the header after the title tag:

    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    <html lang="en">
    <title>Page! - Test</title>
    <?php require("inc/header.php"); ?>
    Thanks for all your help!


  14. #14
    Join Date
    Jan 2005
    Alicante (Spain)
    If you use the following if the page is called dogs.php the title will be dogs:
    PHP Code:
    <title><?php print(str_replace('.php'''$_SERVER['SCRIPT_NAME'])); ?></title>
    Last edited by bokeh; 04-12-2005 at 02:32 PM.

  15. #15
    Join Date
    Feb 2005
    BC, Canada
    $titles['index.php'] => 'Main';
    $titles['whatever.php'] => 'TEST';

    echo $titles[basename($_SERVER['PHP_SELF'])];

    Put that in your header file then make a title value for each page.

    [Oops] Just read you have it finished. Sorry.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.66374 seconds
  • Memory Usage 3,031KB
  • Queries Executed 13 (?)
More Information
Template Usage (33):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (12)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (15)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (15)postbit
  • (15)postbit_onlinestatus
  • (15)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (70):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates