1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Have new script. Need dynamic titles.

Discussion in 'PHP' started by ozband, Jul 14, 2005.

  1. #1
    Hi all,

    I am a relative young one when it comes to php, so here goes.

    I have just acquired a nice little guitar tab script. But the big let down is the page titles. They are all the same. I need Dynamic Titles.

    Everything goes off the index page, by that i mean when you click on an artist, you get the following url - site.xxx/index.php?m=a&a=bandname

    then when i click on a certain tab for the band, i get a url of site.xxx/index.php?m=s&lid=2

    Most of the code seems to be in the index.php file, with includes being top.php, functions.php, commonhtml.php.

    The title tags are in the template.htm which is used for the layout.

    So, what Im asking is there any way to do this?? I see forums do it like php-nuke and this one. Just wondering what the procedure is?

    Is it a case of getting a bit of code? Or is this format not capable?

    Any tutorials on getting custom titles throughout a php site would be most appreciated.

    Thank you all.

    P.S. What price range would I be looking at, to get somebody to do this?? Just need a general quote if possible. Thanks.
     
    ozband, Jul 14, 2005 IP
  2. Pyrrhonist

    Pyrrhonist Peon

    Messages:
    5
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Well, you've got a couple options here. If the only thing you want to change in your title is the band-name, probably the easiest thing to do is just substitute the band name into the title element with something like this:
    <title><?php echo $_GET['a'] . " Guitar Tabs"; ?> </title>
    PHP:
    Or if you want to get a bit more complicated (but still not incredibly hard) you can create a breadcrubs file which contains the structure and then use a php case statement to load a different tiitle based on the page that's being loaded.

    If you go that way, all you have to do is this:
    <title><?php include("breadcrumbs.inc.php"); ?></title>
    PHP:
    Where your breadcrumbs file would look something like this:
    
    switch(strtolower($_GET['m'])) {
        case "m":                 // m is just what you provided for your top lvl query
        switch(strtolower($_GET['a'])) {
             case "band1":
                  echo "This is my custom title for band1";
             break;
             case "band2":
                 echo "this is my custom title for band2";
             break;
             default:
                 echo "This is the default title attribute;
             break;
        default:
             echo "This is the default title for when the menu doesn't equal m";
        break;
    }
    
    PHP:
    If you want to start changing more elements on the page, you can set the breadcrumbs file to load before any other page loads, and then assign each sub-element to a variable to be echoed where you choose.

    I do this quite often when approaching a site that doesn't have a built-in mechanism for customizing titles, and find that it works quite well as a patch.

    If you're still not sure about how to do this, please send me a PM, and I would be happy to contract it for you (and I'm quite reasonable)
     
    Pyrrhonist, Jul 14, 2005 IP
    ozband likes this.
  3. ozband

    ozband Active Member

    Messages:
    408
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    78
    #3
    Hi,

    When using this code

    <title><?php echo $_GET['a'] . " Guitar Tabs"; ?> </title> 
    
    PHP:
    The result was desireable for the artist name. The only problem was I could not get it to show up in the title of the page as only the code showed. I tried it in the template between the header tags and it was no good. What can I do about that?



    That is perfect for the title I am after "BandName Guitar Tabs" .

    It would be perfect if it could go a step further to "Songname Guitar Tabs" If at all possible??

    Thanks all for your help. :)
     
    ozband, Jul 14, 2005 IP
  4. ozband

    ozband Active Member

    Messages:
    408
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    78
    #4
    Ok now, I have gotten as far as

    Bandname - Album Guitar Tabs

    by using

    <title><?php  echo $_GET['a'] . " - ";  echo $_GET['al'] . " Guitar Tabs"; ?> </title> 
    PHP:
    Now, the song names go by track numbers, but i need the song names so I can get

    Bandname - Album - songname Guitar Tabs

    or

    Bandname - songname Guitar Tabs

    <title><?php  echo $_GET['a'] . " - ";  echo $_GET['al'] . " - ";   echo $_GET['WHAT GOES HERE'] . " Guitar Tabs "; ?> </title> 
    PHP:
    So heres the last snag,

    having lid there gets me the track number. lets say its 2, the url is tabs/index.php?m=s&lid=2

    this gives me a title of - 2 - Guitar Tabs

    i need to know what goes there.

    Also, is there an if statement or alike that can give a slogan for pages without the a, and al, ie. the home page.

    Thanks all for helping. :)
     
    ozband, Jul 14, 2005 IP
  5. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #5
    To help I'd have to see how your DB is set up. Basically if you have track # 2 you would then have to pull the actual title out of your database to display it. as for checking if you are at the home page, you can check if the a al variable exist
    if (!isset($_GET['a'])) {
        // we are at a page without 'a'
    }
    PHP:
    If you want to check if you're at the actual home page, you can do
    
    if ('/' == dirname($_SERVER['SERVER_NAME'])) {
        // we are at the homepage for your domain.
    }
    PHP:
     
    exam, Jul 14, 2005 IP
  6. ozband

    ozband Active Member

    Messages:
    408
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    78
    #6
    thanks for that.

    I think the best bet would be to hire someone. lol As Im not the best at this...

    Anyhow, here is the code to maketables.php . This file makes the DB for the tab script.

    
    
    <?php
    $link = mysql_connect("localhost","user","pass");
    
    
    mysql_select_db("DB_name");
    
    mysql_query("drop table tabs_users");
    mysql_query("drop table tabs");
    
            $sqlqry = "create table tabs(lid BIGINT(255) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, artist VARCHAR(255) NOT NULL, album VARCHAR(255), track INT(3) UNSIGNED, song VARCHAR(255) NOT NULL, added_uid BIGINT(255) UNSIGNED NOT NULL, added_date DATETIME, corrected_uid BIGINT(30) UNSIGNED, corrected_date DATETIME, tabs LONGTEXT NOT NULL);";
    if (mysql_query($sqlqry)) {
                 echo "Created tabs<br>";
            } else {
                 echo "Failed - ";
                 echo mysql_error()."<br>";
            }
    
            $sqlqry = "create table tabs_users(uid BIGINT(255) UNSIGNED PRIMARY KEY AUTO_INCREMENT NOT NULL, username VARCHAR(255) NOT NULL, passwd VARCHAR(255) NOT NULL, firstname VARCHAR(255), lastname VARCHAR(255), email VARCHAR(255) NOT NULL, location VARCHAR(255), dateregistered DATE NOT NULL, privread INT(1) UNSIGNED NOT NULL DEFAULT 1, privwrite INT(1) UNSIGNED NOT NULL DEFAULT 1, privcorrect INT(1) UNSIGNED NOT NULL DEFAULT 1, privdeleteown INT(1) UNSIGNED NOT NULL DEFAULT 1, privdeleteany INT(1) UNSIGNED NOT NULL DEFAULT 0, priveditusers INT(1) UNSIGNED NOT NULL DEFAULT 0, priveditconfig INT(1) UNSIGNED NOT NULL DEFAULT 0, active INT(1) UNSIGNED NOT NULL DEFAULT 1, banned INT(1) UNSIGNED NOT NULL DEFAULT 0, posts INT(255) UNSIGNED NOT NULL DEFAULT 0);";
    if (mysql_query($sqlqry)) {
                 echo "Created tabs users<br>";
            } else {
                 echo "Failed - ";
                 echo mysql_error()."<br>";
            }
    
    mysql_close($link);
    ?>
    
    
    PHP:
     
    ozband, Jul 24, 2005 IP
  7. J.D.

    J.D. Peon

    Messages:
    1,198
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Imagine somebody constructing this link to your site:

    yoursite.com?a=insert-any-profanity

    and now imagine SE's indexing it. The point is - always validate the input. Make sure the name of the band is a valid string.

    Also, always use htmlspecialchars if you echo back user input. Otherwise somebody can inject any HTML into your page.

    J.D.
     
    J.D., Jul 24, 2005 IP
  8. ozband

    ozband Active Member

    Messages:
    408
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    78
    #8
    Oh thats worrying... Would you all suggest I get a different script??

    This just doesnt seem too SEO friendly to me?
     
    ozband, Jul 25, 2005 IP
  9. J.D.

    J.D. Peon

    Messages:
    1,198
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #9
    I'm not saying anything about the script - I didn't look too much into it. Just this line caught my attention. Essentially, all the input you get must be validated and encoded, if echoed back. For example, if you change your code to this

    <title><?php echo htmlspecialchars(check_a($_GET['a'])) . " Guitar Tabs"; ?> </title>
    PHP:
    , check_a, your function, would check that the value of $_GET['a'] is indeed a valid band, lesson, whatever. This will prevent people from messing with your titles; htmlspecialchars will encode things like '<' and '>', which can be used for cross-site scripting attacks.

    J.D.
     
    J.D., Jul 25, 2005 IP
  10. ozband

    ozband Active Member

    Messages:
    408
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    78
    #10
    Thank you very much... I appreciate your help.. Obviously Im a novice when it comes to php.. lol

    Anyone want to give me a quote for what I seek?? I really need this done as I have a great domain ready to have content added, but do not want to add thousands of pages all with the same title, as you all may understand.

    I do not want to place a price as I do not know what that would be worth.

    Thanks.
     
    ozband, Jul 25, 2005 IP
  11. ozband

    ozband Active Member

    Messages:
    408
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    78
    #11
    Ok,

    Here is the code for the index.php file. Maybe someone can see some code that could be used to extract the desired title. I have also added the file which is used to add the tabs. This has a few if statements which makes it only allow NUMBERS to be entered in track field. What I was thinking is to change that field to add the song name and call to it like I did for the band name and album. But I need it to allow letters and also have to get rid of song field...

    If anyone sees a way to do this, or an even better way, I would much appreciate it.
     

    Attached Files:

    ozband, Jul 25, 2005 IP
  12. ozband

    ozband Active Member

    Messages:
    408
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    78
    #12
    Bump.....


    WILL PAY FOR SERVICES.....
     
    ozband, Aug 2, 2005 IP
  13. J.D.

    J.D. Peon

    Messages:
    1,198
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Have you sorted things out or you still need help on this?
     
    J.D., Aug 5, 2005 IP