SitePoint Sponsor

User Tag List

Results 1 to 11 of 11

Thread: Cookie question

  1. #1
    SitePoint Addict will_'s Avatar
    Join Date
    Apr 2004
    Location
    Asheville, NC
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cookie question

    I am trying to track the referring pages that brought visitors to our site. Here is the cookie I have set:

    $referer = getenv('HTTP_REFERER');
    $value = $referer;
    setcookie("cookiename", $value, time()+3600);

    This works great if there was a referrer in the HTTP request, but if there wasn't, it bombs out when the page is loaded:
    Notice: Undefined index: cookiename in D:\xxx\farnam\xxx\index.php on line 50

    How do I set up a null value in the cookie using an if/else statement if there is no referrer?

    Thanks for any help!

  2. #2
    Non-Member Gator99's Avatar
    Join Date
    Sep 2004
    Location
    Florida
    Posts
    613
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Change line two to:
    PHP Code:
    ($referer) ? ($value $referer) : ($value="None"); 

  3. #3
    Non-Member Icheb's Avatar
    Join Date
    Mar 2003
    Location
    Germany
    Posts
    1,474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by will_
    $referer = getenv('HTTP_REFERER');
    $value = $referer;
    setcookie("cookiename", $value, time()+3600);
    Why on God's earth do you first put the value in $referer, then again in $value and then use $value to put it in the cookie?

    And what do you mean by "tracking referer pages"? Why not just populate a database with the values, so you don't have to bother the client with this work?

  4. #4
    SitePoint Addict will_'s Avatar
    Join Date
    Apr 2004
    Location
    Asheville, NC
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Icheb
    Why on God's earth do you first put the value in $referer, then again in $value and then use $value to put it in the cookie?
    Because I am in the process of learning how to do this. Better ideas are welcome

    Quote Originally Posted by Icheb
    And what do you mean by "tracking referer pages"? Why not just populate a database with the values, so you don't have to bother the client with this work?
    I am using the referer only as a test scenario. When all is working, I am going to actually be tracking the QUERY_STRING that brought visitors to the web site via a search engine. That is, if there was a query in the first place.

    Then, I will be taking that QUERY_STRING and sending it in a hidden form field when a visitor fills out the Contact Us form. In the end, the client and the SEO will know what search terms are generating sales leads on the site.

  5. #5
    SitePoint Addict will_'s Avatar
    Join Date
    Apr 2004
    Location
    Asheville, NC
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Gator99
    Change line two to:
    PHP Code:
    ($referer) ? ($value $referer) : ($value="None"); 
    Thanks...that seems to do the trick.

  6. #6
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    There's professional ad tracking solutions out there, that aren't very expensive, that handle this task more gracefully. AdWatcher is one of them. Google Analytics does a decent job at goal tracking too.

  7. #7
    Non-Member Icheb's Avatar
    Join Date
    Mar 2003
    Location
    Germany
    Posts
    1,474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Again, why not just populate a database with these values? Hardly everyone will use the contact form and it's more important to know which search terms lead people to your site in general.
    So just check the query string for search terms on every page and then store those in a table in the database.

  8. #8
    SitePoint Addict will_'s Avatar
    Join Date
    Apr 2004
    Location
    Asheville, NC
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Icheb
    Again, why not just populate a database with these values? Hardly everyone will use the contact form and it's more important to know which search terms lead people to your site in general.
    So just check the query string for search terms on every page and then store those in a table in the database.
    These decisions are not mine to make, unfortunately. I just work here.

    The client currently uses formsite.com to manage their form. I know there are better ways to do it, but they like this one and are stuck in their bad habits. They want the search queries to appear in the formsite.com admin page, so that it is all in one place. They have no database on their server to my knowledge. We can already track all search queries using Analog/Webalizer. The valuable info for the SEO, for whatever reason, is knowing exactly which queries bring contacts, not knowing what all the queries are. I think he is interested in seeing which keywords are working, which are of use to better optimize for, and which aren't generating any leads at all.

    As for using existing analytic tools, they do that already, but nothing tracks query strings that lead to Contact Us submissions. At least that we know of, anyway.

  9. #9
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Assuming you mean query strings in the referring URL, then all the major analytic tools do. If you mean in your own URL, then that means you are asking different sites to link to you with different URLs. That's no different than giving them a tracking URL from the analytics tool.

  10. #10
    SitePoint Addict will_'s Avatar
    Join Date
    Apr 2004
    Location
    Asheville, NC
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dan Grossman
    Assuming you mean query strings in the referring URL, then all the major analytic tools do. If you mean in your own URL, then that means you are asking different sites to link to you with different URLs. That's no different than giving them a tracking URL from the analytics tool.
    I am referring to query strings in the referring URL. But what they want to know is the association between Contact Us emails and query strings. And they want it all in one place, which is the formsite.com admin panel. That's why I am passing this via the Contact Us form in a hidden field.

  11. #11
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by will_
    And they want it all in one place, which is the formsite.com admin panel
    Then that's the only thing stopping them from using a professional solution with all the metrics one can provide.


Bookmarks

Posting Permissions

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