Welcome to Geeklog, Anonymous Friday, November 29 2024 @ 12:42 pm EST

Geeklog Forums

no http:// in "Referrer Back Links" Block


The Referrer

Anonymous
Hi!

I've downloaded said script from http://www.squatty.com (and upgraded it a little).

It's a great script, but some referrers don't include "http://" in them (I have no idea, how it's even possible, but the facts talk for themselves).
That causes a bug so they do look fine in the log text file, but when you actually see the block in the browser, it displays them as blanks.
For example:
...5
bla.com...4
gfdgd.com...6
...2
ds45.org...8

See the sites that referred 5 and 2 people respectively?
Exactly.

I've asked in squatty's forum how can it be fixed, but just as I've observed in the past - squatty's forum is dead.

Therefore, I'll be grateful if someone here can pick up the glove and suggest a solution.

Here's what I added to lib-custom.php (again, it's my exclusive modified code):
Text Formatted Code

function countElements($needle, $haystack)
{
    $match = 0;
    foreach($haystack as $key => $value) {
        if($needle == $value)
            $match ++;
    }
    return $match;
}

function phpblock_referrers() {
    global $_CONF;
    require_once($_CONF['path'] . 'reflog.php');

    $reflog = $_CONF['path'] . 'reflog.txt';
    $rfile = file($reflog);                             // read the referrer log into an array

    $tmpArray = array();
    $output = "";                                       //  start constructing output string

    if(count($rfile) > 0) {                             //  if file is non-empty
        foreach($rfile as $r) {
            $refLink = chop($r);                        //  chop trailing whitespace
            $tmp = parse_url($refLink);
            $refName = $tmp['host'];                    //  extract domain name from string
            $hostArray[] = $refName;                    //  array of domain names
            $linkArray[] = $refLink;                    //  array of URL
        }

        $uniqueElements = array_unique($hostArray);     //  get unique referring domains

        foreach($uniqueElements as $key=>$value) {      //  get hits per domain, assign to hitsArray[]
            $count = countElements($value, $hostArray);
            $hitsArray[] =  array($value, $count);
        }

        foreach($hitsArray as $key=>$value) {           //  match up unique domains, hits, and 1 URL for each
            $matchKey = array_search($value[0], $hostArray);
            $outputArray[] = array($value[0], $linkArray[$matchKey], $value[1]);
        }

        uasort($outputArray,compare1);
        $output .= "<p><table width="50%" border="0">n";
        $output .= "<tr><td><b>Referrer</b></td><td><b>Hits</b></td></tr>";
        while(list($key, $val) = each($outputArray)) {
            $urlName = substr($val[0], 0, 25);
            //place strings to search for here
            $search = array("www.", "sourceforge", "mail.");
            //Replace strings with
            $replace = array("", "sf", "");
            $urlName = str_replace($search, $replace, $urlName);
            $urlHits = $val[2];
            $output .= "<tr><td><a href="$val[1]" target=_blank>$urlName</a></td>";
            $output .=  "<td align=right>$urlHits</td></tr>";
        }
        $output .="</table>";
    } else
        $output .= "No recent referrersn";
    return $output;
}

function compare1($arg1, $arg2)
{
    if ($arg1[2] > $arg2[2])
        return -1;
    elseif ($arg1[2] < $arg2[2])
        return 1;
    return 0;
}

 


And then, here's the script itself (reflog.php):
Text Formatted Code

<?php
// "Referrer Back Links"
// Originally by: http://www.squatty.com - Version: 0.2 - Date: 08.25.02
// Modified by: http://lior.weissbrod.com  - Date: 24/12/2003

$path = '/geeklog/';

// Name of referrer log file
$reflog = $path . 'reflog.txt';

// Name of semaphore file
$semaphore = $path . 'reflog.tmp';

// Maximum number of referrers to log
$maxref = 10;

// Domain name of this site (minus "http://www.")
$mydomain = 'weissbrod.com';

// From whence did Bunky come?
$ref = getenv("HTTP_REFERER");

// Cover me. I'm going in.

if (($ref) and (!strstr($ref, $mydomain))) {
// if there's a referrer, and it's not someone bouncing around this site
        $ref .= "n";                             // append a line feed
        $sp = fopen($semaphore, "w");           // open the semaphore file
        if (flock($sp, 2)) {                  // lock the semaphore; other processes will stop and wait here
                $rfile = file($reflog);         // read the referrer log into an array
                if ($ref <> $rfile[0]) { // if this referrer is different from the last one
                        if (count($rfile) == $maxref)           // if the file is full
                                array_pop($rfile);              // pop the last element
                        array_unshift($rfile, $ref);            // push the new referrer onto the front
                        $r = join("", $rfile);                  // make the array into a string
                        $rp = fopen($reflog, "w");              // open the referrer log in write mode
                        $status = fwrite($rp, $r);              // write out the referrer URLs
                        $status = fclose($rp);          // close the log
                }
        }
        $status = fclose($sp);  // close the semaphore (and release the lock)
}
?>

 


Now please tell me - how can I enforce "http://" if there isn't
one already?

P.S.
Is there a way in the world to enter it all directly into lib-custom.php instead of using 2 scripts (I've tried and failed so it's not that easy...)?

Come on, this is your chance to prove you make a better forum than them...

Thanks a lot!
 Quote

Status: offline

squatty

Forum User
Full Member
Registered: 01/21/02
Posts: 269

I've asked in squatty's forum how can it be fixed, but just as I've observed in the past - squatty's forum is dead.


Quite the opposite.  The squatty.com forum and website have been and continue to be a source of Geeklog information.  We've been online for over 2 years now.  New messages are posted daily!

Not all forum topics are replied to.  Especially ones that request custom php coding for FREE.   There are several options available for custom php/Geeklog development.  When all else fails, try those outlets.

To answer your question, why not try the Visitor Stats plugin in place of the Referrer Block.  The Vstats plugin also has a referrer block and  it does a better job of handling HTTP headers.  With a little reverse engineering on your part, you might be even find the answer to your original question.
In a world without walls and fences, who needs Windows and Gates?
 Quote

The Referrer

Anonymous
Well, my question is more about PHP than Geeklog (since the script already works fine and just needs tweaking).

I assume a solution won't take more than 1-2 lines of code
(in plain english:
if not url(1-7)="http://" then
url="http://" + url )

And it's just something that would make my little (and free) blog more complete (those blank URLs are just look weird)...

P.S.
If only you answered so quickly in your forum too (well, sorry, I've never gotten a reply there for anything...)

Thanks!
 Quote

Status: offline

Blaine

Forum User
Moderator
Registered: 07/16/02
Posts: 1232
Location:Canada
You might want to look at the substr() function.

BTW, Squatty spends a great deal of time helping others and critism does not make me want to go out of my way to help anyone either Rolling Eyes
Geeklog components by PortalParts -- www.portalparts.com
 Quote

Status: offline

ScurvyDawg

Forum User
Full Member
Registered: 11/06/02
Posts: 523
With you on that one Blaine.

I know from experience that if Squatty has the answer and the time he is always willing to share from his experience.

Have you asked TheMike he wrote the code you are Referring to Referrer.
 Quote

Status: offline

THEMike

Forum User
Moderator
Registered: 07/25/03
Posts: 141
Location:Sheffield, UK
I don't think they are refering to my module Scurveydawg, but they could try it:

http://www.*censored*ingbrit.com/filemgmt/visit.php?lid=30

It seems to work fine with all referers I've seen.
 Quote

The Referrer

Anonymous
I followed ScurvyDawg's link and found the "Link Referer Plugin". I decided to continue investigating and found on TheMike's site a plug-in called "http_referer for Geeklog" (only then did I come back here to found that the programmer himself gave away the link...).

So anyway, I downloaded it and it looked really different than "Referrer Back Links".
Am I right, TheMike?

The problem was that I couldn't check that out because there was no screenshot and TheMike himself doesn't use it in his own site.

So is there a site out there that uses it for me to check it out?

P.S.
Blaine, stop being like those crybaby actors who moan about movie critics...

I'm sure squatty here is a fine man, but everytime I ask some question about his scripts, I don't get a reply.
As a fellow webmaster, I think I'd be kind of rude to this to my users.
And it is my right to complain.
Be it as it may, I mean no harm and I think that people should learn to listen and admit (and later fix) their possible mistakes.

That's it.

Thanks!

P.S. 2
So does anyone have an idea how to fix the "http://" part? :-)
 Quote

Status: offline

drshakagee

Forum User
Full Member
Registered: 10/01/03
Posts: 231
Quote by The ReferrerRazz.S. 2
So does anyone have an idea how to fix the "http://" part? :-)

Yes
Yes I am mental.
 Quote

All times are EST. The time is now 12:42 pm.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content