Results 1 to 11 of 11

Thread: Getting Keyword

  1. #1

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Getting Keyword

    I have a few questions.

    I have a script that searches the database for a zip code and displays the matching results of names etc.

    Is there a way i can track what zipcodes are being entered in another database? Also, what other information can i get? How do i get the URL, etc.

    On a side note.

    I use google adwords to get traffic to my sites, is there a way to get the keyword that was used to get to my site?
    Maybe put some type of code in the index.html file?

    Thanks for all your help.

  2. #2
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Getting Keyword

    From your previous script we were working with i added some stuff to store the searches:

    PHP Code:
    <form action="#" method="POST">
        <input type="text" name="zipcode">
        <input type="submit" name="Search">
    </form>
    <br><br><br>
    <?php
    if(isset($_POST['zipcode'])){
        require_once (
    'connect.php');
        require_once (
    'opendb.php');
        
        
    $zipcode $_POST['zipcode'];
        
    $ip $_SERVER['REMOTE_ADDR'];
        
        
    $query "INSERT INTO `searched_zips` SET `zip`='$zipcode', `ip`='$ip'";
        
    $result mysql_query($query);
        
        
    $query "SELECT * FROM search_data WHERE zipcode='$zipcode'";
        
    $result mysql_query ($query);
        
    $count mysql_num_rows($result); //number of results
        
        
    if ($count == 0){
            echo 
    "Nothing";
        } else if(
    $count == 1){
            echo 
    "REDIRECT";
        } else{
            echo 
    "Located $count result(s).<br /><br />\n";
            while(
    $row mysql_fetch_array($result)){
                echo 
    "<p>" $row['zipcode'] . '<br>' $row['company_name'] . '<br>' $row['redirect_url'] . '<br>' $row['notes_1'] . '</p>';
            } 
        }
    } else {
        echo 
    "Please Use Search Form Above!";
    }
    ?>
    My usual boring signature: Something

  3. #3
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Getting Keyword

    As for your side note:

    Most search engines use the GET method for their searches, so it would be something like:
    Code:
    http://www.google.com/search?q=MY+SEARCH
    Thats Google's url.

    To determine how the user got to your site you need the url they came from:
    PHP Code:
    $url $_SERVER['HTTP_REFERER']; 
    I am not quite sure how to explode it to get the base URL or the query.
    Last edited by dclamp; Jul 11th, 2007 at 06:54 PM.
    My usual boring signature: Something

  4. #4

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Re: Getting Keyword

    Quote Originally Posted by dclamp
    From your previous script we were working with i added some stuff to store the searches:

    PHP Code:
    <form action="#" method="POST">
        <input type="text" name="zipcode">
        <input type="submit" name="Search">
    </form>
    <br><br><br>
    <?php
    if(isset($_POST['zipcode'])){
        require_once (
    'connect.php');
        require_once (
    'opendb.php');
        
        
    $zipcode $_POST['zipcode'];
        
    $ip $_SERVER['REMOTE_ADDR'];
        
        
    $query "INSERT INTO `searched_zips` SET `zip`='$zipcode', `ip`='$ip'";
        
    $result mysql_query($query);
        
        
    $query "SELECT * FROM search_data WHERE zipcode='$zipcode'";
        
    $result mysql_query ($query);
        
    $count mysql_num_rows($result); //number of results
        
        
    if ($count == 0){
            echo 
    "Nothing";
        } else if(
    $count == 1){
            echo 
    "REDIRECT";
        } else{
            echo 
    "Located $count result(s).<br /><br />\n";
            while(
    $row mysql_fetch_array($result)){
                echo 
    "<p>" $row['zipcode'] . '<br>' $row['company_name'] . '<br>' $row['redirect_url'] . '<br>' $row['notes_1'] . '</p>';
            } 
        }
    } else {
        echo 
    "Please Use Search Form Above!";
    }
    ?>

    How do i enter the time and date at the same time as the searched zip is being entered into the database?

  5. #5
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Getting Keyword

    PHP Code:
    date(); 
    My usual boring signature: Something

  6. #6
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: Getting Keyword

    Quote Originally Posted by dclamp
    PHP Code:
    $query "INSERT INTO `searched_zips` SET `zip`='$zipcode', `ip`='$ip'"
    that's wrong. an insert query does not have the same syntax as an update query.
    Code:
    INSERT INTO table (field1, field2, field3) VALUES('value1', 'value2', 'value3');
    to insert a date, just save the date and insert it as well. I don't understand the question, unless you just don't know how to make a date. look up the date() function, if so.

  7. #7
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Getting Keyword

    @kows:

    I have been using that syntax for my code, and it works fine for me
    My usual boring signature: Something

  8. #8
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: Getting Keyword

    hm, I guess it does. wonder when that happened; as far as I know, it didn't work a few years ago. either way.

    also, use parse_url() if you're wanting to break down an HTTP referrer into different segments.

  9. #9
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Getting Keyword

    how would you use parse_url()?. I will check php.net as well
    My usual boring signature: Something

  10. #10
    Hyperactive Member
    Join Date
    Dec 2006
    Location
    Ubuntu Haters Club
    Posts
    405

    Re: Getting Keyword

    parse_url returns an associative array of the url's details.

    PHP Code:
    print_r(parse_url('http://www.google.com/search?q=MY+SEARCH')); 
    Code:
    Array
    (
        [scheme] => http
        [host] => www.google.com
        [path] => /search
        [query] => q=MY+SEARCH
    )
    » Twitter: @rudi_visser : Website: www.rudiv.se «

    If Apple fixes security flaws, they are heralded as proactive. If Microsoft fixes a security flaw, they finally got around to fixing their buggy OS.

  11. #11
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Getting Keyword

    ah! that seems simple thanks
    My usual boring signature: Something

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width