Anyone good with PHP? I got an error...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Goodings Media
    Confirmed User
    • Apr 2007
    • 1987

    #1

    Anyone good with PHP? I got an error...

    Well not an error as such. My site isn't logging the incoming hits from my refferrals properly, and as I used someone else package to install my site (I know fuck all about PHP) I don't quite know whats wrong lol

    This is the section from my index file that is supposed to log whether a user came from a referrals link or not.

    // See if this visitor was referred by a link on your list
    if ($linktrading==1){

    if(!isset($_SESSION['referral'])) {
    $referral = $_SERVER['HTTP_REFERER'];
    $array=parse_url($referral);
    $referral1 = $array['host'];
    $referral2 = str_replace("www.", "", $referral1);
    $referral3 = "http://".trim($referral2);
    $referral4 = "http://www.".$referral2;
    // If referrer is in database, then add a hit!
    $add_hit = mysql_query("update links
    set totalin=totalin+1,
    dayin=dayin+1
    where url like '$referral1%' || url like '$referral3%' || url like '$referral4%'");
    $_SESSION['referral'] = 1;
    }

    }
    // End link check

    The script is PHP Link dropper if anyone is interested, thanks
    ICQ: 446-568-913 Email: liam||goodingsmedia.com msn: [email protected]
  • Goodings Media
    Confirmed User
    • Apr 2007
    • 1987

    #2
    yeah Ive just been playing, and it seems that if a person comes from one of these sites, then it adds a refferral to ALL of the sites in my link list.
    ICQ: 446-568-913 Email: liam||goodingsmedia.com msn: [email protected]

    Comment

    • Dynamix
      G F Y not
      • Jan 2004
      • 2910

      #3
      You might try replacing with the below code. I make no guarantees but the MySQL query above is very sloppy.. this may just be the fix:

      Code:
      // See if this visitor was referred by a link on your list
      if ($linktrading==1){
      
      if(!isset($_SESSION['referral'])) {
      $referral = $_SERVER['HTTP_REFERER'];
      $array=parse_url($referral);
      $referral1 = $array['host'];
      $referral2 = str_replace("www.", "", $referral1);
      $referral3 = "http://".trim($referral2);
      $referral4 = "http://www.".$referral2;
      // If referrer is in database, then add a hit!
      $sql = "UPDATE `links` SET totalin=totalin+1, dayin=dayin+1 WHERE (`url` like '".$referral1."%' or `url` like '".$referral3."%' or `url` like '".$referral4."%' ";
      $add_hit = mysql_query($sql);
      $_SESSION['referral'] = 1;
      }
      
      }
      // End link check

      TGPFactory Full TGP Design & Installation Services
      ICQ 250 142 484 · AIM TGPDynamix · Email: patrick (at) tgpfactory (dot) com
      See who I am at AdultWhosWho.com!

      Comment

      • Goodings Media
        Confirmed User
        • Apr 2007
        • 1987

        #4
        hiya thanks, off to try it now
        ICQ: 446-568-913 Email: liam||goodingsmedia.com msn: [email protected]

        Comment

        • Goodings Media
          Confirmed User
          • Apr 2007
          • 1987

          #5
          hiya, thanks but it broke it lol Its not registering any hits now.

          Any ideas?
          ICQ: 446-568-913 Email: liam||goodingsmedia.com msn: [email protected]

          Comment

          • Dynamix
            G F Y not
            • Jan 2004
            • 2910

            #6
            Eek! I'd have to look at the database to know for sure, likely what's happening is somewhere in the query your programmer has made a slight mistake that is returning all rows in the table as ones it should increment, rather than just the referring URL entry.

            TGPFactory Full TGP Design & Installation Services
            ICQ 250 142 484 · AIM TGPDynamix · Email: patrick (at) tgpfactory (dot) com
            See who I am at AdultWhosWho.com!

            Comment

            • sarettah
              see you later, I'm gone
              • Oct 2002
              • 14297

              #7
              Originally posted by Dynamix
              You might try replacing with the below code. I make no guarantees but the MySQL query above is very sloppy.. this may just be the fix:

              Code:
              // See if this visitor was referred by a link on your list
              if ($linktrading==1){
              
              if(!isset($_SESSION['referral'])) {
              $referral = $_SERVER['HTTP_REFERER'];
              $array=parse_url($referral);
              $referral1 = $array['host'];
              $referral2 = str_replace("www.", "", $referral1);
              $referral3 = "http://".trim($referral2);
              $referral4 = "http://www.".$referral2;
              // If referrer is in database, then add a hit!
              $sql = "UPDATE `links` SET totalin=totalin+1, dayin=dayin+1 WHERE (`url` like '".$referral1."%' or `url` like '".$referral3."%' or `url` like '".$referral4."%' ";
              $add_hit = mysql_query($sql);
              $_SESSION['referral'] = 1;
              }
              
              }
              // End link check
              Shouldn't need the single quotes around links or url in the query and since you have the where clause inside a paren you need to close the paren.

              $sql = "UPDATE links SET totalin=totalin+1, dayin=dayin+1 WHERE (url like '".$referral1."%' or url like '".$referral3."%' or url like '".$referral4."%')";
              All cookies cleared!

              Comment

              • Goodings Media
                Confirmed User
                • Apr 2007
                • 1987

                #8
                Originally posted by sarettah
                Shouldn't need the single quotes around links or url in the query and since you have the where clause inside a paren you need to close the paren.

                $sql = "UPDATE links SET totalin=totalin+1, dayin=dayin+1 WHERE (url like '".$referral1."%' or url like '".$referral3."%' or url like '".$referral4."%')";
                Hiya,

                that put it back to how it was before

                Looking at the "links" table....

                the fields for each row is..

                id, title, url, email, dayin, totalin, dayout, totalout.

                Each row has data in it for 1 individual site.

                So how do I make that SQL query just +1 to the row that corresponds to the refferral URL? This section is the only part of the entire sites PHP that I can find that refers to it
                ICQ: 446-568-913 Email: liam||goodingsmedia.com msn: [email protected]

                Comment

                • sarettah
                  see you later, I'm gone
                  • Oct 2002
                  • 14297

                  #9
                  Originally posted by Goodings Media
                  Hiya,

                  that put it back to how it was before

                  Looking at the "links" table....

                  the fields for each row is..

                  id, title, url, email, dayin, totalin, dayout, totalout.

                  Each row has data in it for 1 individual site.

                  So how do I make that SQL query just +1 to the row that corresponds to the refferral URL? This section is the only part of the entire sites PHP that I can find that refers to it
                  Yeah, all I did was tell how to fix the syntax error that was stopping it from updating

                  Ok, first of all, it would be handy to look at the data in the data base, how you have the trade sites set up in the links table.

                  What your script is doing is building a base url for any referral string passed in. so:

                  If the referral string is http://www.domain1.com/ what comes out is:
                  referral1: www.domain1.com
                  referral2: domain1.com
                  referral3: http://domain1.com
                  referral4: http://www.domain1.com

                  If the referral string is a sub directory of the domain, we would still just get the base out:

                  referral string: http://www.domain1.com/lesbians/whateverpage.html
                  referral1: www.domain1.com
                  referral2: domain1.com
                  referral3: http://domain1.com
                  referral4: http://www.domain1.com

                  Then the script attempts to update any records that look like any of the referral strings. So, basically anything that belongs to domain1.com in your table is getting updated with the count.

                  so if you had:

                  record1 www.domain1.com
                  record2 www.domain1.com/subdirectory1/
                  record3 www.domain1.com/subdirectory2/
                  record4 www.domain1.com/subdirectory3/

                  Then all records would have the counts updated with the update query that is being used.

                  So, the script you are using is assuming that there will only be one record in the links table for each domain. This should work as long as you are tracking at the domain level and not trying to trade with sites at the subdomain/subdirectory level.

                  So, like I say, a look at the data would help a touch

                  test page demonstrating what I am saying:

                  http://www.partyafterdark.com/refertest.php

                  If you are actually trying to track at a sub directory level then what you need to do to the script is add the path component to the mix:

                  $referral = $_SERVER['HTTP_REFERER'];
                  $array=parse_url($referral);
                  $referral1 = $array['host'] . $array['path'];
                  $referral2 = str_replace("www.", "", $referral1) . $array['path'];
                  $referral3 = "http://".trim($referral2) . $array['path'];
                  $referral4 = "http://www.".$referral2 . $array['path'];

                  That will now only update those that look like domain.com/path. But remember, if there is no path on the referral string it is going to update anything that starts with the base domain of domain.com.

                  It would be much better to go deeper and instead of using a "like" in the query, only update exact matches. If you are in control of the links table then you can guarantee exactly how the url in the links table will look and can force the exact match. If you are allowing folks to add their own trades to the links table then you lose some of that control or have to force it programmatically.

                  To do the exact match, on the update query you would say:

                  $sql = "UPDATE links SET totalin=totalin+1, dayin=dayin+1 WHERE (url='" . $referral1 . "' or url='" . $referral2 . "' or url='" . $referral3 . "' or url='" . $referral4. "')";

                  Still, this is allowing for the url in the links table to be any of 4 variants: domain.com, www.domain.com, http://domain.com or http://www.domain.com

                  Thus, if all 4 variants exist in the table, then all 4 will get updated.

                  It would be better to force the exact phrasing of the url and have it in the table in a consistent manner. such as domain1.com. That way you only have to worry about matching one variant of the domain and can force the query to only update one record.

                  something like:

                  $referral = $_SERVER['HTTP_REFERER'];
                  $array=parse_url($referral);
                  $referral1 = $array['host'] . $array['path'];

                  "update links set yada=yada, yada1=yada1 where url='" . referral1 . "'";

                  That would remove most of the ambiguity from the update query.
                  All cookies cleared!

                  Comment

                  • sarettah
                    see you later, I'm gone
                    • Oct 2002
                    • 14297

                    #10
                    After a touch more thought.

                    When you are testing, how are you doing it? If you are just going to the browser and typing the url in the address bar, then you could be getting an empty referral string. The output for that would be:

                    referral1 (blank)
                    referral2 (blank)
                    referral3 http://
                    referral4 http://www.

                    This would match any record in the database every time and would update every record.

                    for a test: cut and paste this into your address bar http://www.partyafterdark.com/refertest1.php

                    You should see a blank referral string coming out. Referral is set, but it is empty.

                    Then go click on the url above and you should see the referral string coming out as gofuckyourself.com (actually all 4 variants of it)

                    However, if you have software that is allowing you to surf anonymously, it could be blanking out the referral string and you would be getting the blank string again.

                    however, if in the code you added a condition to the if that is checking the referral string, then blank referral strings could be blocked from coming in and would no longer update all records.


                    if(!isset($_SESSION['referral']) and $_SESSION['referral']>'')

                    http://www.partyafterdark.com/refertest2.php has the new condition in it. If you click it you should see a good referral string, if you cut an paste it into the browser you should see a message saying referral string is blank. edited in: I have something screwed up in there so it might not work propely, will have it fixed in a minute.
                    Last edited by sarettah; 04-17-2007, 07:00 AM.
                    All cookies cleared!

                    Comment

                    • sarettah
                      see you later, I'm gone
                      • Oct 2002
                      • 14297

                      #11
                      Ok, I screwed up the if condition duh..

                      should be

                      if(!isset($_SESSION['referral']) and $_SERVER['HTTP_REFERER'] >' ' )
                      All cookies cleared!

                      Comment

                      • Goodings Media
                        Confirmed User
                        • Apr 2007
                        • 1987

                        #12
                        dude, this is awesome! :D

                        Thanks a load, gonna take me about an hour to get my head around all of this! Off to look in the mySQL now....
                        ICQ: 446-568-913 Email: liam||goodingsmedia.com msn: [email protected]

                        Comment

                        • Goodings Media
                          Confirmed User
                          • Apr 2007
                          • 1987

                          #13
                          hiya, in the table the majority are .....

                          http://www.domain.com

                          The ones that aren't, I can change and then from now on include in the form that the link needs to be "http://www....."

                          Also, adding the support to match subdomains as well is.

                          This code right?

                          Code:
                          $referral = $_SERVER['HTTP_REFERER'];
                          $array=parse_url($referral);
                          $referral1 = $array['host'] . $array['path'];
                          $referral2 = str_replace("www.", "", $referral1) . $array['path'];
                          $referral3 = "http://".trim($referral2) . $array['path'];
                          $referral4 = "http://www.".$referral2 . $array['path'];
                          The problem isn't just between subdomains though, its as if EVERY row, gets 1 hit added when I get a hit from ANY refferral.

                          Changing the statement to EXACT matches rather than like sounds like it's worth a shot.

                          I follow how it would mix up subdomains and domains, but still not sure why it adds one to EVERY row.... so I guess it's a case of give this one a shot and see
                          ICQ: 446-568-913 Email: liam||goodingsmedia.com msn: [email protected]

                          Comment

                          • Goodings Media
                            Confirmed User
                            • Apr 2007
                            • 1987

                            #14
                            Code:
                            if(!isset($_SESSION['referral']) and $_SERVER['HTTP_REFERER'] >' ' )
                            THIS FIXED IT!!!!

                            It must have just bee taking anything that had "http://..." or "www..." or "..." or "http://www...."

                            Seriously dude, a legend! Anytime your in Kent, look me up! Theres a few pints with your name on em! :D
                            ICQ: 446-568-913 Email: liam||goodingsmedia.com msn: [email protected]

                            Comment

                            • sarettah
                              see you later, I'm gone
                              • Oct 2002
                              • 14297

                              #15
                              np...
                              All cookies cleared!

                              Comment

                              • ilovehelping
                                Registered User
                                • Apr 2007
                                • 8

                                #16
                                check these people

                                Hi

                                check with these people, they are good at programing

                                [email protected]


                                Thank you,
                                ilovehelping

                                Comment

                                Working...