Hallo zusammen,
ich hoffe es kann mir hier jemand helfen.
Ich möchte gern dieses PHP Script zum laufen bringen...
<?php
//problems? suggestions? email the author!
//
// nathan@ncyoung.com
//get most linked to pages on site
//select count(visitURL) as count, visitURL from referer_visitLog group by visitURL order by count desc
mysql_connect("dbHost", "dbUser", "dbPass");
mysql_select_db("dbName");
if ($refererList){
print "referers:<BR>";
$ar = refererList($refererList,"global");
print join("<BR>",$ar);
}
if ($topRefererList){
print join("<BR>",topRefererList($topRefererList,"global"));
}
function logReferer(){
$currentURL = $_SERVER['REQUEST_URI'];
$fullCurrentURL = "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
$ref = getenv('HTTP_REFERER');
if (!$ref){
dbg("no referer");
return;
}
if ($ref != strip_tags($ref)){
//then they have tried something funny,
//putting HTML or PHP into the HTTP_REFERER
dbg("bad char in referer");
return;
}
$ignore = Array(
'your domain',
'http://www.myelin.co.nz/ecosystem/bot.php',
'http://radio.xmlstoragesystem.com/rcsPublic/',
'http://blogdex.media.mit.edu//',
'http://subhonker6.userland.com/rcsPublic/',
'mastadonte.com',
);
foreach ($ignore as $site){
if (stristr($ref, $site)){
dbg("referer ignored");
return;
}
}
$doubleCheckReferers = 0;
if ($doubleCheckReferers){
dbg("loading referering page");
//this is so that the page up until the call to
//logReferer will get shown before it tries to check
//back against the refering URL.
flush();
$goodReferer = 0;
$fp = @fopen ($ref, "r");
if ($fp){
//timeout after 5 seconds
socket_set_timeout($fp, 5);
while (!feof ($fp)) {
$page .= trim(fgets($fp));
}
if (strstr($page,$fullCurrentURL)){
dbg("found current url in page");
$goodReferer = 1;
}
}
if(!$goodReferer){
dbg("did not find \n\n:$fullCurrentURL:\n in \n\n\n :$page: \n\n\n");
return;
}
}
$anchor = preg_replace("/http:\/\//i", "", $ref);
$anchor = preg_replace("/^www\./i", "", $anchor);
$anchor = preg_replace("/\/.*/i", "", $anchor);
$sql ="insert into referer_visitLog (referingURL,baseDomain,visitURL) values ('$ref','$anchor','$currentURL')";
//print $sql;
mysql_query($sql);
}
function refererList ($howMany=5,$visitURL=""){
$i=2;
$ret = Array();
//if no visitURL, will show links to current page.
//if url given, will show links to that page.
//if url="global" will show links to all pages
if (!$visitURL){
$visitURL = $_SERVER['REQUEST_URI'];
}
if ($visitURL == "global"){
$sqr_recentReferer = mysql_query("select * from referer_visitLog order by visitID desc");
}
else {
$sqr_recentReferer = mysql_query("select * from referer_visitLog where visitURL = '$visitURL' order by visitID desc");
}
while($result_row = mysql_fetch_array($sqr_recentReferer)){
$fullUrl = $result_row['referingURL'];
$domain = $result_row['baseDomain'];
if (!$domain){
continue;
}
if ($last[$domain]){
continue;
}
$last[$domain] = 1;
$temp = "<a href=\"$fullUrl\" target=\"_blank\">$domain</a>";
array_push($ret,$temp);
if ($i++ > $howMany){
break;
}
}
return $ret;
}
function topRefererList ($howMany=5,$visitURL=""){
$i=2;
$ret = Array();
//see refererList() for notes.
if (!$visitURL){
$visitURL = $_SERVER['REQUEST_URI'];
}
if ($visitURL == "global"){
$sqr_recentReferer = mysql_query("select Count(referer_visitLog.baseDomain) as totalHits, referer_visitLog.baseDomain from referer_visitLog group by referer_visitLog.baseDomain order by totalHits desc limit $howMany");
}
else {
$sqr_recentReferer = mysql_query("select Count(referer_visitLog.baseDomain) as totalHits, referer_visitLog.baseDomain from referer_visitLog where visitURL = '$visitURL' group by referer_visitLog.baseDomain order by totalHits desc limit $howMany");
}
while($result_row = mysql_fetch_array($sqr_recentReferer)){
$count = $result_row['totalHits'];
$domain = $result_row['baseDomain'];
$uSet = mysql_query("select * from referer_visitLog where baseDomain = '$domain' order by visitID desc");
$uRow = mysql_fetch_array($uSet);
$latestUrl = $uRow["referingURL"];
$temp = "<a href=\"$latestUrl\" target=\"_blank\">$domain</a> ($count)";
array_push($ret,$temp);
if ($i++ > $howMany){
break;
}
}
return $ret;
}
function dbg($string){
//print $string . "<BR>\n";
}
if ($createTable){
print "Creating table:<BR>";
mysql_query("
create table referer_visitLog (
visitID int auto_increment,
primary key (visitID),
visitTime timestamp,
visitURL char(250),
referingURL char(250),
baseDomain char(250)
)
") or print "could not create table, might it exist?";
}
/*
Usage:
You must include the library in order to use it. Issue the include statement once on each page in which you want to use this library, before you call any of the functions. A typical include statement would be:
include("refererLib.php");
To log the referers visiting a given page, place this code on the page:
logReferer();
To show a list of 5 pages that link to the current page (ordered by most recent visit) place this code:
$list = refererList(5);
foreach ($list as $link){
print "$link<BR>";
}
To show a list of the outside links most commonly used to get to the current page:
$list = topRefererList(5);
foreach ($list as $link){
print "$link<BR>";
}
In both cases, you can ask for a global list, i.e. a list of recent or top referers for all pages on your site that log referers:
$list = refererList(5,"global");
foreach ($list as $link){
print "$link<BR>";
}
Or:
$list = topRefererList(5,"global");
foreach ($list as $link){
print "$link<BR>";
}
*/
?>
Diese Tabellen habe ich angelegt
reate table referer_visitLog (
visitID int auto_increment,
primary key (visitID),
visitTime timestamp,
visitURL char(250),
referingURL char(250),
baseDomain char(250)
den include befehl sowie logReferer(); habe ich auch gesetzt!
Wenn ich nun eine Liste anzeigen lassen will bekommen ich immer folgenden Fehler -->
mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /kunden/....../refererLib.php on line 131
Kann es sein das ich noch Tabellen anlegen muss?
Vielen Dank für eure Hilfe!
Gruß
Matthias
ich hoffe es kann mir hier jemand helfen.
Ich möchte gern dieses PHP Script zum laufen bringen...
<?php
//problems? suggestions? email the author!
//
// nathan@ncyoung.com
//get most linked to pages on site
//select count(visitURL) as count, visitURL from referer_visitLog group by visitURL order by count desc
mysql_connect("dbHost", "dbUser", "dbPass");
mysql_select_db("dbName");
if ($refererList){
print "referers:<BR>";
$ar = refererList($refererList,"global");
print join("<BR>",$ar);
}
if ($topRefererList){
print join("<BR>",topRefererList($topRefererList,"global"));
}
function logReferer(){
$currentURL = $_SERVER['REQUEST_URI'];
$fullCurrentURL = "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
$ref = getenv('HTTP_REFERER');
if (!$ref){
dbg("no referer");
return;
}
if ($ref != strip_tags($ref)){
//then they have tried something funny,
//putting HTML or PHP into the HTTP_REFERER
dbg("bad char in referer");
return;
}
$ignore = Array(
'your domain',
'http://www.myelin.co.nz/ecosystem/bot.php',
'http://radio.xmlstoragesystem.com/rcsPublic/',
'http://blogdex.media.mit.edu//',
'http://subhonker6.userland.com/rcsPublic/',
'mastadonte.com',
);
foreach ($ignore as $site){
if (stristr($ref, $site)){
dbg("referer ignored");
return;
}
}
$doubleCheckReferers = 0;
if ($doubleCheckReferers){
dbg("loading referering page");
//this is so that the page up until the call to
//logReferer will get shown before it tries to check
//back against the refering URL.
flush();
$goodReferer = 0;
$fp = @fopen ($ref, "r");
if ($fp){
//timeout after 5 seconds
socket_set_timeout($fp, 5);
while (!feof ($fp)) {
$page .= trim(fgets($fp));
}
if (strstr($page,$fullCurrentURL)){
dbg("found current url in page");
$goodReferer = 1;
}
}
if(!$goodReferer){
dbg("did not find \n\n:$fullCurrentURL:\n in \n\n\n :$page: \n\n\n");
return;
}
}
$anchor = preg_replace("/http:\/\//i", "", $ref);
$anchor = preg_replace("/^www\./i", "", $anchor);
$anchor = preg_replace("/\/.*/i", "", $anchor);
$sql ="insert into referer_visitLog (referingURL,baseDomain,visitURL) values ('$ref','$anchor','$currentURL')";
//print $sql;
mysql_query($sql);
}
function refererList ($howMany=5,$visitURL=""){
$i=2;
$ret = Array();
//if no visitURL, will show links to current page.
//if url given, will show links to that page.
//if url="global" will show links to all pages
if (!$visitURL){
$visitURL = $_SERVER['REQUEST_URI'];
}
if ($visitURL == "global"){
$sqr_recentReferer = mysql_query("select * from referer_visitLog order by visitID desc");
}
else {
$sqr_recentReferer = mysql_query("select * from referer_visitLog where visitURL = '$visitURL' order by visitID desc");
}
while($result_row = mysql_fetch_array($sqr_recentReferer)){
$fullUrl = $result_row['referingURL'];
$domain = $result_row['baseDomain'];
if (!$domain){
continue;
}
if ($last[$domain]){
continue;
}
$last[$domain] = 1;
$temp = "<a href=\"$fullUrl\" target=\"_blank\">$domain</a>";
array_push($ret,$temp);
if ($i++ > $howMany){
break;
}
}
return $ret;
}
function topRefererList ($howMany=5,$visitURL=""){
$i=2;
$ret = Array();
//see refererList() for notes.
if (!$visitURL){
$visitURL = $_SERVER['REQUEST_URI'];
}
if ($visitURL == "global"){
$sqr_recentReferer = mysql_query("select Count(referer_visitLog.baseDomain) as totalHits, referer_visitLog.baseDomain from referer_visitLog group by referer_visitLog.baseDomain order by totalHits desc limit $howMany");
}
else {
$sqr_recentReferer = mysql_query("select Count(referer_visitLog.baseDomain) as totalHits, referer_visitLog.baseDomain from referer_visitLog where visitURL = '$visitURL' group by referer_visitLog.baseDomain order by totalHits desc limit $howMany");
}
while($result_row = mysql_fetch_array($sqr_recentReferer)){
$count = $result_row['totalHits'];
$domain = $result_row['baseDomain'];
$uSet = mysql_query("select * from referer_visitLog where baseDomain = '$domain' order by visitID desc");
$uRow = mysql_fetch_array($uSet);
$latestUrl = $uRow["referingURL"];
$temp = "<a href=\"$latestUrl\" target=\"_blank\">$domain</a> ($count)";
array_push($ret,$temp);
if ($i++ > $howMany){
break;
}
}
return $ret;
}
function dbg($string){
//print $string . "<BR>\n";
}
if ($createTable){
print "Creating table:<BR>";
mysql_query("
create table referer_visitLog (
visitID int auto_increment,
primary key (visitID),
visitTime timestamp,
visitURL char(250),
referingURL char(250),
baseDomain char(250)
)
") or print "could not create table, might it exist?";
}
/*
Usage:
You must include the library in order to use it. Issue the include statement once on each page in which you want to use this library, before you call any of the functions. A typical include statement would be:
include("refererLib.php");
To log the referers visiting a given page, place this code on the page:
logReferer();
To show a list of 5 pages that link to the current page (ordered by most recent visit) place this code:
$list = refererList(5);
foreach ($list as $link){
print "$link<BR>";
}
To show a list of the outside links most commonly used to get to the current page:
$list = topRefererList(5);
foreach ($list as $link){
print "$link<BR>";
}
In both cases, you can ask for a global list, i.e. a list of recent or top referers for all pages on your site that log referers:
$list = refererList(5,"global");
foreach ($list as $link){
print "$link<BR>";
}
Or:
$list = topRefererList(5,"global");
foreach ($list as $link){
print "$link<BR>";
}
*/
?>
Diese Tabellen habe ich angelegt
reate table referer_visitLog (
visitID int auto_increment,
primary key (visitID),
visitTime timestamp,
visitURL char(250),
referingURL char(250),
baseDomain char(250)
den include befehl sowie logReferer(); habe ich auch gesetzt!
Wenn ich nun eine Liste anzeigen lassen will bekommen ich immer folgenden Fehler -->
mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /kunden/....../refererLib.php on line 131
Kann es sein das ich noch Tabellen anlegen muss?
Vielen Dank für eure Hilfe!
Gruß
Matthias
Kommentar