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.

Simple PHP script to generate page title based upon searchers keywords?

Discussion in 'PHP' started by xcentrix, Oct 23, 2006.

  1. #1
    Hi,

    I am trying to find a simple PHP script to do the following:

    1. Searcher types "big blue widgets model 3344" into google.com

    2. My URL comes up in the SERPS and the searcher clicks on it.

    3. When my page loads I want the searcher to see his keywords as the title of the page.

    Any ideas?

    thanks,

    x
     
    xcentrix, Oct 23, 2006 IP
  2. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I don't know of any scripts to do this automatically, but it shouldn't be too hard.

    I'd simply look at the referer URL and pull it apart to grab the original search query.
     
    TwistMyArm, Oct 24, 2006 IP
  3. Nickwiz

    Nickwiz Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    There are lots of scripts doing this (or similar).
    Have done it myself in several sites.
    If you know regexp it should not be hard to solve taking point from $_SERVER['HTTP_REFERER'] as mentioned by TwistMyArm.

    Else;

    Read:
    http://alistapart.com/articles/searchhighlight/
    http://suda.co.uk/projects/SEHL/

    http://dev.wp-plugins.org/file/google-highlight/trunk/google-hilite.php?rev=204

    Modify to your needs and you'r dig.
     
    Nickwiz, Oct 24, 2006 IP
  4. JEET

    JEET Notable Member

    Messages:
    3,825
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #4
    This should get you started:

    <?php
    $refurl = getenv("HTTP_REFERER");
    $googleterm= explode("&q=", $refurl);
    $q= $googleterm['1'];
    if(trim($q) == "")
    {
    $googleterm= explode("&p=", $refurl);
    $q= $googleterm['1'];
    }
    $q= str_replace("+", " ", $q);

    print '
    <html><head><title>'. $q. '</title>
    ';
    ?>
    Rest of page.


    Secondly, I am not sure how this is going to help you in anyway. Google won't index your site by searching it's own site first. If your site doesn't have a <title> at the time google indexed you, I am not very sure if they are going to rank you in SERPs.
    They use your title to be displayed in the link which searcher clicks.
    Bye :)
     
    JEET, Oct 24, 2006 IP
  5. Mystique

    Mystique Well-Known Member

    Messages:
    2,579
    Likes Received:
    94
    Best Answers:
    2
    Trophy Points:
    195
    #5
    Interesting JEET, I'm just implement Google search results on-site instead of new window and this piece of code comes handy for the purpose.

    Thanks for posting :)
     
    Mystique, Oct 24, 2006 IP
  6. JEET

    JEET Notable Member

    Messages:
    3,825
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #6
    Don't forget to credit me! ;) :D
    By the way, are you talking about on-page for adsense search box?

     
    JEET, Oct 24, 2006 IP
    Mystique likes this.
  7. Mystique

    Mystique Well-Known Member

    Messages:
    2,579
    Likes Received:
    94
    Best Answers:
    2
    Trophy Points:
    195
    #7
    Yes I'm talking about that search box.

    I know I can't manipulate the results as per AdSense TOS but I will like to display the original query in a side column with other search tools so people who could not find it in Google take other options without lose track of the original query.

    Of course I will credit you, and in the meantime sending you some rep ;)
     
    Mystique, Oct 24, 2006 IP
  8. JEET

    JEET Notable Member

    Messages:
    3,825
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #8
    Be careful with what you are planning to do...
    I read in terms that:
    You cannot populate the search box,
    You cannot use search box with competitor services.

    Don't risk anything you have...
    Thanks for the rep! :)
    Bye :)
     
    JEET, Oct 25, 2006 IP