Domain Manage

php help

Discussion in 'SEO Search Engine Optimisation' started by ScottJ, Jan 26, 2009.

Thread Status:
Not open for further replies.
  1. ScottJ United Kingdom

    ScottJ Well-Known Member

    Joined:
    Nov 2005
    Posts:
    1,406
    Likes Received:
    13
    Wonder if any of you can help, I am looking for the little bit of php code that would basically say

    If the url of the page is domain.co.uk/product.php?search+term
    Then display "this text"

    Just looking to add some text on a specific page that uses a template so can't hard code it.
     
  2. Domain Forum

    Acorn Domains Elite Member

    Joined:
    1999
    Messages:
    Many
    Likes Received:
    Lots
     
  3. accelerator United Kingdom

    accelerator Well-Known Member

    Joined:
    Apr 2005
    Posts:
    7,397
    Likes Received:
    109
    I would advise asking at phpfreaks.com/forums, they will give you the code.

    Rgds
     
  4. fraser United Kingdom

    fraser Active Member

    Joined:
    Nov 2005
    Posts:
    200
    Likes Received:
    2
    Scott - not sure exactly what you are looking for, can you explain again and I'll help if I can.

    Is this just on one page or throughout the site?

    Do you want to display the search term or some other text?
     
  5. Jeewhizz

    Jeewhizz Well-Known Member

    Joined:
    May 2006
    Posts:
    1,177
    Likes Received:
    18
    On product.php put this:

    PHP:
    <?php
    if($_SERVER['QUERY_STRING']=='search+term') {
      echo 
    "this text";
    }
    ?>
    Jee
     
  6. ScottJ United Kingdom

    ScottJ Well-Known Member

    Joined:
    Nov 2005
    Posts:
    1,406
    Likes Received:
    13
    In Lumens - renewable energy efficient contemporary lighting I created categories using search terms like bathroom lights, I'd like to add some text to those category pages so if the page was:

    /productlist.php?q=bathroom+light

    I want to add a paragraph of text to help make the page more unique.

    Edit: Thanks Jee I'll give that a whirl!
     
    Last edited: Jan 26, 2009
  7. fraser United Kingdom

    fraser Active Member

    Joined:
    Nov 2005
    Posts:
    200
    Likes Received:
    2
    ah I get it now :) Looks like Jee has it sorted for you anyway!
     
  8. Jeewhizz

    Jeewhizz Well-Known Member

    Joined:
    May 2006
    Posts:
    1,177
    Likes Received:
    18
    Now that changes things slightly ;)

    PHP:
    <?php
    if($_GET['q']=='bathroom light') {
      echo 
    'abc';
    }
    ?>
     
  9. Skinner

    Skinner Well-Known Member

    Joined:
    Jul 2008
    Posts:
    4,324
    Likes Received:
    80
    Hell of a long way of doing that if there are multiple items.

    PHP:
    switch (strtolower($_GET['q'])) { //without the strtolower bathroom, Bathroom, BathRoom are all different terms
    //you shouldnt really accept user inputted data directly as it allow code injection so sanitize the q variable first.
        
    case "bathroom light":
            echo 
    'This is a bathroom light';
        break;
            
        case 
    "toilet light":
            echo 
    'this is a toilet light';
        break;

        default:
            echo 
    'default product';
        break;
    }
    Would be more suitable for a product guide.

    I use this kinda switch to draw data from a mysql database on queries but can be used this way too.
     
  10. ScottJ United Kingdom

    ScottJ Well-Known Member

    Joined:
    Nov 2005
    Posts:
    1,406
    Likes Received:
    13
    Interesting, thanks very much for the help folks.
     
  11. ScottJ United Kingdom

    ScottJ Well-Known Member

    Joined:
    Nov 2005
    Posts:
    1,406
    Likes Received:
    13
    One last thing, is there a way to only make the text appear in
    this url : productlist.php?q=bathroom+light
    and not
    this one: productlist.php?q=bathroom+light&iListOffset=10
     
  12. Skinner

    Skinner Well-Known Member

    Joined:
    Jul 2008
    Posts:
    4,324
    Likes Received:
    80
    You would need to use Mod_Rewrite to do that the easiest way, otherwise you would need to edit the pagination code to use sessions, cookies or post data instead to track what page of the search results you was up to.

    I suck at mod_rewrite (and regex) but a quick search of the net will tell you most you need to know.

    Unless its proprietry software you may find that someone has already made SEO friendly URLs for it, much like this forum uses :)
     
  13. Jeewhizz

    Jeewhizz Well-Known Member

    Joined:
    May 2006
    Posts:
    1,177
    Likes Received:
    18
    PHP:
    <?php
    if(strtolower($_GET['q'])=='bathroom light' && !isset($_GET['iListOffset'])) {
      echo 
    'abc';
    }
    ?> 
    Try that...
     
  14. Skinner

    Skinner Well-Known Member

    Joined:
    Jul 2008
    Posts:
    4,324
    Likes Received:
    80
    o0o I think I misread your post :p

    I thought you meant modify the URL in the browser not the output, I was on the phone when I read it.

    Yeah the above should work by jee :)

    Maybe worth testing for the value of 'iListOffset', incase someone deletes just the numerical value to get back the homepage.
     
  15. ScottJ United Kingdom

    ScottJ Well-Known Member

    Joined:
    Nov 2005
    Posts:
    1,406
    Likes Received:
    13
    That works perfectly Jee, many thanks mate!
     
Thread Status:
Not open for further replies.

Share This Page