WEB php question about dynamic meta tags

Discussion in 'OT Technology' started by shaitaan, Jun 22, 2008.

  1. shaitaan

    shaitaan New Member

    Joined:
    Jul 12, 2002
    Messages:
    49,620
    Likes Received:
    0
    Location:
    Bay Area, CA / NYC
    Hey guys,

    I have a common header.php file, which includes the title, meta etc. tags.

    However, by default, all pages that use the common header.php file will have the same title/meta tags/etc.

    I found this article:

    http://www.hawkee.com/snippet/3640/

    which lets me dynamically insert the right title/tags based on the page name; however, I can't figure out how to make it work for pages under different folders. This seems to only work for pages at the root level.

    Help please? :hsd: :x:
     
  2. retorq

    retorq What up bitch??

    Joined:
    Dec 14, 2006
    Messages:
    6,061
    Likes Received:
    0
    Location:
    Mohave Desert
    I bet it's absolute vs relative paths to the meta.php file...
     
  3. o2

    o2 Witty Title Here OT Supporter

    Joined:
    Oct 4, 2005
    Messages:
    16,099
    Likes Received:
    12
    Location:
    Toronto
    meta tags are pretty much useless today.

    try this?

    <? include("../file.php"); ?>
     
  4. shaitaan

    shaitaan New Member

    Joined:
    Jul 12, 2002
    Messages:
    49,620
    Likes Received:
    0
    Location:
    Bay Area, CA / NYC

    didn't work :(
     
  5. shaitaan

    shaitaan New Member

    Joined:
    Jul 12, 2002
    Messages:
    49,620
    Likes Received:
    0
    Location:
    Bay Area, CA / NYC

    i can do that, and have an include for every single page..but if i were to do that much, i might as well hard code the meta tags/title/etc :o
     
  6. shaitaan

    shaitaan New Member

    Joined:
    Jul 12, 2002
    Messages:
    49,620
    Likes Received:
    0
    Location:
    Bay Area, CA / NYC
    if anyone has any ideas on how to modify get-meta.php to also include for directory, that'd be sweet :o

    Code:
    <?php
    
    $database = 'meta_tags.txt';
    $meta_db = fopen($database, 'r');
    
    $page = $_SERVER['SCRIPT_NAME'];
    $page = substr($page, 1);
    
    while($data = fgetcsv($meta_db, 9000, '|'))
    {
    	if($data[0] == $page)
    	{
                    $title = $data[1];
    		$meta_keywords = $data[2];
    		$meta_description = $data[3];
    	}
    }
    
    ?>
    
    
     
  7. o2

    o2 Witty Title Here OT Supporter

    Joined:
    Oct 4, 2005
    Messages:
    16,099
    Likes Received:
    12
    Location:
    Toronto
    if a file calls get-meta.php and its not in the dirctory, there is nothing you can do. either do an absolute path from the start, or suffer.
     
  8. shaitaan

    shaitaan New Member

    Joined:
    Jul 12, 2002
    Messages:
    49,620
    Likes Received:
    0
    Location:
    Bay Area, CA / NYC
    ....

    so youre saying there's no way to have a centralized location for meta tags for sites that use a directory structure?

    I dunno about that....

    I'm not tied to using get-meta.php. can you explain your absolute path idea a bit more?
     
  9. o2

    o2 Witty Title Here OT Supporter

    Joined:
    Oct 4, 2005
    Messages:
    16,099
    Likes Received:
    12
    Location:
    Toronto
    absolute path to the file
    usually something like

    /home/username/public/file.php


    you can include that in any directory, and it will be loaded.
     
  10. biawokauns

    biawokauns New Member

    Joined:
    Sep 18, 2001
    Messages:
    19,893
    Likes Received:
    0
    Location:
    Republic of Kalifornia
    thats not entirely true :o
     
  11. Slid.

    Slid. I'm a guy.

    Joined:
    Oct 25, 2001
    Messages:
    1,928
    Likes Received:
    0
    Location:
    NH
  12. shaitaan

    shaitaan New Member

    Joined:
    Jul 12, 2002
    Messages:
    49,620
    Likes Received:
    0
    Location:
    Bay Area, CA / NYC


    :coold:

    $20 paypal if someone wants to help me figure this out? :hsd:
     
  13. Josh

    Josh Guest

    I actually do this a different way
    ..


    In the spot where the title and meta info is I have a script that checks for a var $newTitle. IF it exists it uses that as the title, if not it uses the default. Then on each of my dynamic pages I have this right before the header include

    global $newTitle;
    $newTitle = "whatever";

    I used the script to generate an appropriate title based on the content for that page
     
  14. shaitaan

    shaitaan New Member

    Joined:
    Jul 12, 2002
    Messages:
    49,620
    Likes Received:
    0
    Location:
    Bay Area, CA / NYC
    interesting...coudl you share your script? or is that confidential :o
     
  15. Josh

    Josh Guest

    what I posted above is basically it..

    do you know any PHP?

     
  16. o2

    o2 Witty Title Here OT Supporter

    Joined:
    Oct 4, 2005
    Messages:
    16,099
    Likes Received:
    12
    Location:
    Toronto
    why do this stupid work around to fix bad code? just replace the code with something simple + better, than doing these stupid work arounds.
     
  17. Josh

    Josh Guest

    my method has nothing to do with his code, it was a solution in itself
     
  18. Slid.

    Slid. I'm a guy.

    Joined:
    Oct 25, 2001
    Messages:
    1,928
    Likes Received:
    0
    Location:
    NH
    Basically if you have a whole site set up and you want to do the meta-directory thing you really only need to modify the header file to do a switch based on 'SCRIPT_NAME'.

    And yeah, it's kinda messy I guess but if you're already vested in a certain structure then whav.

    http://www.linksling.com/ot/
    http://www.linksling.com/ot/cake/
    http://www.linksling.com/ot/muffin/

    my directory structure:

    /ot/cake/
    -index.php

    /ot/muffin/
    -index.php

    /ot/
    -index.php
    -header.php

    index.php:
    Code:
    <?
    	
    	// this is the full path to your base directory
    	$rootDir = $_SERVER['DOCUMENT_ROOT'] . '/ot/';
    			
    	include_once($rootDir . 'header.php');
    
    ?>
    
    header.php:
    Code:
    <?
    
    	if($_SERVER['SCRIPT_NAME']) {
    	
    		// turn directory into array
    		$csDir = explode('/', $_SERVER['SCRIPT_NAME']);
    				
    		$dir1 = $csDir[1];
    		$dir2 = $csDir[2];
    		
    		// my directory structure is /ot/<meta-directory>
    		// i don't care about the first directory (ot) so i
    		// create my meta tags based off the second directory
    		// if you use this in the root folder of your web server
    		// you'll want to switch ($dir1) as opposed to switch ($dir2)
    		
    		switch ($dir2) {
    		
    			case "cake":
    			  $metaTag = "cake related meta tags";
    			break;
    			
    			case "muffin":
    			  $metaTag = "muffin related meta tags";
    			break;
    		
    		}
    	
    	}
    	
    	// default meta tag, root folder
    	if(!$metaTag) $metaTag = "default / home";
    
    	print "I am a common header.<br><br>";
    	print "This is my META tag: " . $metaTag;
    
    ?>
    
     

Share This Page