hi

i am new at this list and php...

can anybody help me with my problem:

i would like to show last 10 referres at my website.

now it writes to reflog.txt:

http://www.foo.bar/link_to_my_site.html

and to show-refs.php is

<a
href="http://www.foo.bar/link_to_my_site.html";>http://www.foo.bar/link_to_my
_site.html</a>


i would like that it writes like this:

<a
href="http://www.foo.bar/link_to_my_site.html";>www.foo.bar/link_to_my_site.h
tml</a>

and maximum lenght should be 40. If url is longer, it shoud be

<a
href="http://www.foo.bar/very_long_link_to_my_site.html";>www.foo.bar/very_lo
ng_link_to_my_site....</a>



i have use these files:
///////////////////////////////////////////////
lgf-reflog.php:

<?php
/*
 --------------------------------------------
  LGF Referrer Log
  By Charles F. Johnson
  Copyright 2001 LGF Web Design
  All Rights Reserved.
  http://littlegreenfootballs.com

  This file may be freely distributed
  as long as the credits and copyright
  message above remain intact.
 --------------------------------------------
*/

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

// Name of semaphore file
$semaphore = 'semaphore.ref';

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

// Domain name of this site (minus "http://www.";)
$mydomain = 'tuurna.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)
}
?>

//////////////////////////////////////////////

show-refs.php:

<?php
/*
 --------------------------------------------
  LGF Referrer Log Display Page
  By Charles Johnson
  Copyright 2001 LGF Web Design
  All Rights Reserved.
  http://littlegreenfootballs.com

  This file may be freely distributed
  as long as the credits and copyright
  message above remain intact.
 --------------------------------------------
*/

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

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd";>
<html>
<head>
<title>Last 50 Referrers</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
body {
  background-color: #FFFFFF;
}
p {
  font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
  font-size: 10px;
  line-height: 14px;
  color: #000000;
}
</style>
</head>

<body>
<?php
$rfile = file($reflog);             // read the referrer log into an array
echo "<p>\n";
foreach ($rfile as $r) {            // loop through the array
 $r = chop($r);              // remove trailing whitespace
 if ($r <> "Direct request") echo "<a href=\"$r\">$r</a><br />\n"; // if not
a direct request, link it up
}
echo "</p>\n";
?>
</body>
</html>
///////////////////////////////////
semaphore.ref:

empty file
///////////////////////////////////
reflog:

empty file
///////////////////////////////////

-kari t


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to