SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2001
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help w/ Link Count Script

    I need some help with a php/mysql click counting script. Each URL on my site has a unique ID and every time a link is clicked-on, the script adds 1 to the ID's count.

    Unfortunately, the script truncates any URL that contains an ampersand ("&"), at the ampersand, so that the page doesn't load (e.g., "www.somesite.com?section=4&page=15" becomes just "www.somesite.com?section=4").

    Here is an example of the link syntax which calls the click counting script:

    http://www.mysite.com/count.php?ID=2081&url=http://www.somesite.com?section=4&page=15

    Here is the script:

    $url = str_replace("http://", "", $url);
    $url = "http://$url";
    $getit = mysql_query("SELECT * FROM links WHERE ID = '$ID'") or die(mysql_error());
    if(mysql_num_rows($getit) <= 0){
    mysql_query("INSERT INTO links (ID) VALUES ('$ID')") or die(mysql_error());
    header ("Location: $url");
    }
    else{
    mysql_query("UPDATE links SET hits = hits + 1 WHERE ID = '$ID'") or die(mysql_error());
    header ("Location: $url");
    }

    Is there a quick fix?

  2. #2
    SitePoint Wizard Aes's Avatar
    Join Date
    Jun 2001
    Location
    Oklahoma
    Posts
    3,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why do you remove the http:// from the $url and then add it again? That seems needless. Perhaps the str_replace() is removing the & from the $url.

    Otherwise the script doesn't look erroneous -- I'll take a look into whether str_replace() or header() have any issues with & -- but I'm doubtful.
    Colin Anderson
    Ambition is a poor excuse for those without
    sense enough to be lazy.

  3. #3
    What's HTML?
    Join Date
    May 2001
    Location
    San Diego, CA
    Posts
    1,701
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think urlencode() could help with your problem. From what I understand, the & is causing some problems.

    For more information, check out: http://www.php.net/manual/en/function.urlencode.php

    You'll also need to check out htmlentities().
    Ryan Kuhle - A Proud Advisor - Got Questions? Just Ask!
    Get your website started for less than $20! Click Here

  4. #4
    SitePoint Wizard Aes's Avatar
    Join Date
    Jun 2001
    Location
    Oklahoma
    Posts
    3,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by RKuhle
    ... From what I understand, the & is causing some problems ...
    DUH!
    Considering we've all ready established that, it sounds quite funny.
    Colin Anderson
    Ambition is a poor excuse for those without
    sense enough to be lazy.

  5. #5
    What's HTML?
    Join Date
    May 2001
    Location
    San Diego, CA
    Posts
    1,701
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Aes
    DUH!
    Considering we've all ready established that, it sounds quite funny.
    It's not that funny if you checked out the link. It has more information about the specific problem that the & is causing. I think the specific problem is much more useful than saying "Heyuk! Looks like the dern & thingy is causin' some problems there!"
    Ryan Kuhle - A Proud Advisor - Got Questions? Just Ask!
    Get your website started for less than $20! Click Here

  6. #6
    SitePoint Wizard Aes's Avatar
    Join Date
    Jun 2001
    Location
    Oklahoma
    Posts
    3,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by RKuhle
    ... "Heyuk! Looks like the dern & thingy is causin' some problems there!" ...
    Colin Anderson
    Ambition is a poor excuse for those without
    sense enough to be lazy.

  7. #7
    SitePoint Zealot
    Join Date
    Mar 2001
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your help. I've checked out the urlencode() link, but don't really understand how to fix the problem. Any more help?


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
  •