How To Control Meta Tags of Dynamic Pages?

Discussion in 'PHP' started by kashifkb, Jul 17, 2007.

  1. #1
    Hi there,

    I want to know that how to control meta tags (Title, description, Keywords) of the dynamic web pages that are created in php.

    Any help will be appreciated.

    Best Regards
    KB
     
    kashifkb, Jul 17, 2007 IP
  2. convertor

    convertor Peon

    Messages:
    34
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Simply use variables substitution as in other parts of the page.
    <title><?=$this_page_title?></title>
    content of the $this_page_title can come from your database by example.
     
    convertor, Jul 17, 2007 IP
  3. shaan_l

    shaan_l Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    how would you change the title and meta data depending on the name of the file?

    ie if it was index.php display certain information, if it was aboutus.php display other information, etc etc
     
    shaan_l, Jul 18, 2007 IP
  4. AsHinE

    AsHinE Well-Known Member

    Messages:
    240
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    138
    #4
    You can get requested filename from $_SERVER['REQUEST_URI'].
     
    AsHinE, Jul 18, 2007 IP
  5. shaan_l

    shaan_l Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    can you give an example of how it would work?

    n00b here :p
     
    shaan_l, Jul 18, 2007 IP
  6. AsHinE

    AsHinE Well-Known Member

    Messages:
    240
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    138
    #6
    I use like this:
    if ($_SERVER['REQUEST_URI']=="/index.html"  || $_SERVER['REQUEST_URI']=="/"  || strpos( $_SERVER['REQUEST_URI'],"news")) {
    					$title = "onetitle";
    				}else{
    					$title = "othertitle";				}
    PHP:
    It checks whether displayed page is main or URL contains "news" and set appropriate value to $title variable
     
    AsHinE, Jul 18, 2007 IP
  7. nabiha

    nabiha Peon

    Messages:
    111
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #7
    You can use database too to save meta tags and populate based on the pages concerned.
     
    nabiha, Jul 18, 2007 IP
  8. exodus

    exodus Well-Known Member

    Messages:
    1,900
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    165
    #8
    If you create a website dynamicly with php can't you not create dynamic meta tags for that website when you dynamicly created the webpage itself?
     
    exodus, Jul 18, 2007 IP
  9. Corvus

    Corvus Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    I think you should be more specific... what do you mean with "control"
    Maybe you should use mysql or just a simple include.

    Please tell us more details about your needs....
     
    Corvus, Jul 18, 2007 IP
  10. shaan_l

    shaan_l Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    ok cool

    on my homepage (either / or index.php) i want a specific title and meta data to be displayed. when you click on a link to another page on the site, say products.php, the title and meta data must change to what i have made for products.php; then if you click on help the title and meta data must change again.

    all the title and meta data information must be in one file, say meta.php which is included in to all the pages on the site
     
    shaan_l, Jul 18, 2007 IP
  11. hasbehas

    hasbehas Well-Known Member

    Messages:
    726
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    190
    #11
    Think I understand what you mean. I had such problem in the past.
    Though mine is not perfect, it does my job. I have sites over 40-50 pages with this model.

    if your page displayed is ie: mydomain.com/details.php?content=aboutus then your content is aboutus.htm, details.php reads(includes) the htm file and other function reads(includes) aboutus.txt which is the title,desc/keywords

    Long shot, but works for me. is this what you want ?
     
    hasbehas, Jul 19, 2007 IP
  12. shaan_l

    shaan_l Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    yes that sounds like its what i want.

    can you perhaps post the code for how it works?
     
    shaan_l, Jul 19, 2007 IP
  13. hasbehas

    hasbehas Well-Known Member

    Messages:
    726
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    190
    #13
    Sure, have a look..

    in a file called root.php3
    
    //content file
    $htm = ".htm";
    $pid = "$detail$htm";
    function show_detail($pid)
    {
    if (!preg_match("/http/", $pid)) {
    require($pid);
    } else {
       echo "NO no no..!!!";
       die;
    }
    }
    //end
    
    //title file
    $txt = ".txt";
    $title = "$detail$txt";
    function show_title($title)
    {
    if (!preg_match("/http/", $title)) {
    require($title);
    } else {
       echo "NO no no..!!!";
       die;
    }
    }
    //end
    
    PHP:
    and in details.php
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <?
    require("root.php3");
    show_title("$title");
    ............
    .............
    ........
    show_detail("$pid");
    .......
    .......
    </body>
    </html>
    
    PHP:
    the line if (!preg_match("/http/", $pid))

    is needed cos, some bright kid might try to use your domain as his spamming base. if there is http match (yourdomain.com/contents.php?detail=http://spamdomain.com/aboutus.htm or even txt) in the requested file, it stops :D

    Try..
     
    hasbehas, Jul 19, 2007 IP
  14. shaan_l

    shaan_l Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #14
    thanks! i'll give it a try and see how it goes
     
    shaan_l, Jul 19, 2007 IP
  15. hasbehas

    hasbehas Well-Known Member

    Messages:
    726
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    190
    #15
    Just let me know if it works for you.. ;)
     
    hasbehas, Jul 20, 2007 IP