Jump to content

Move to new server-- php script no longer works


jmueller0823

Recommended Posts

Hi There

 

We have a script/process that we use to display popularity

(i.e. Top Ten Articles) of various content groups.

 

Essentially, we're tracking pageviews to a MySQL db,

and then weekly, we create static pages of the totals.

Then, we DELETE the table and start over for the next week.

 

The script has run trouble free for years. Then, we cutover to

a new server and the script no longer works.

 

Specifically, the 'counter' does not increment the count

in the MySQL table. No errors.

 

I'm wondering if there might be a php configuration/compatibility

issue on the new server?

 

I'd appreciate feedback. Thanks.

 

This is how it works:

The code below is placed in the page to be tracked.

<img src="counter.php">

And the script below increments the count

<?

/*

Author: Erik Boeters <[email protected]>
Website: http://westland.ath.cx/

*/

// Database settings
DEFINE("SERVER", "server");
DEFINE("DATABASE", "db");
DEFINE("USERNAME", "user");
DEFINE("DBPASSWORD", "pass");

// IP's you want to ban seperated by spaces
DEFINE("DENYIPS", "");

// Administrator password for the admin interface, example: stats.php?a=vs&password=****
// If no password is given the admin interface will be available to anyone.
DEFINE("ADMINPASSWORD", "image0823");


// Not neccesary to modify.

$db = mysql_connect(SERVER, USERNAME, DBPASSWORD);

function checkPageExits($page) {
    $queryGetPages = "SELECT * FROM pagecounter3";
    $resultGetPages = mysql_db_query(DATABASE, $queryGetPages) or die ("Query failed: error was ".mysql_error());
    while($row=mysql_fetch_array($resultGetPages)) {
        if (stristr($row["page"], $page)) {
            $r = true;
        }
    }
    if ($r) {
        return true;
    } else {
        return  false;
    }
}

function createPageEntry($page) {
    if (isset($page)) {
        $queryGetPages = "INSERT INTO `pagecounter3` (`pageID`, `page`, `visits`) VALUES ('', '$page', '1')";
        $resultGetPages = mysql_db_query(DATABASE, $queryGetPages) or die ("Query failed: error was ".mysql_error());
        return true;
    } else {
        return false;
    }
}

function incrementVisits($page,$ip) {
    $denyips = explode(" ", DENYIPS);
    if (!in_array($ip, $denyips)) {
        if (isset($page)) {
            if (checkPageExits($page)) {
                $queryIncrement = "UPDATE pagecounter3 SET visits = visits + 1 WHERE page='$page'";
                $resultIncrement = mysql_db_query(DATABASE, $queryIncrement) or die ("Query failed: error was ".mysql_error());
                return true;
            } elseif(createPageEntry($page)) {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    } else {
        return false;
    }
}

switch ($a) {
default:
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");  
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header ("Pragma: no-cache"); // HTTP/1.0
header ("Content-type: image/png");
$im = @ImageCreate (30, 10)
or die ("Cannot Initialize new GD image stream");
$white = ImageColorAllocate ($im, 255, 255, 255);
$trans = imagecolortransparent($im,$white);
ImagePng ($im);
incrementVisits ($HTTP_REFERER,$REMOTE_ADDR);
break;

}
mysql_close($db);
?>
?> 

mysql_db_query is deprecated, the manual says not to use it.

 

try this...

 

 

 


<?

/*

Author: Erik Boeters <[email protected]>
Website: http://westland.ath.cx/

*/

// Database settings
DEFINE("SERVER", "server");
DEFINE("DATABASE", "db");
DEFINE("USERNAME", "user");
DEFINE("DBPASSWORD", "pass");

// IP's you want to ban seperated by spaces
DEFINE("DENYIPS", "");

// Administrator password for the admin interface, example: stats.php?a=vs&password=****
// If no password is given the admin interface will be available to anyone.
DEFINE("ADMINPASSWORD", "image0823");


// Not neccesary to modify.

$link = mysql_connect(SERVER, USERNAME, DBPASSWORD);

// make link to database or die
if (!$link) {
    die('Not connected : ' . mysql_error());
}

// select db
$db_selected = mysql_select_db(DATABASE, $link);
if (!$db_selected) {
    die ('Can\'t use '.DATABASE.' : ' . mysql_error());
}

function checkPageExits($page) {
    $queryGetPages = "SELECT * FROM pagecounter3";
    $resultGetPages = mysql_query($queryGetPages) or die ("Query failed: error was ".mysql_error());
    while($row=mysql_fetch_array($resultGetPages)) {
        if (stristr($row["page"], $page)) {
            $r = true;
        }
    }
    if ($r) {
        return true;
    } else {
        return  false;
    }
}

function createPageEntry($page) {
    if (isset($page)) {
        $queryGetPages = "INSERT INTO `pagecounter3` (`pageID`, `page`, `visits`) VALUES ('', '$page', '1')";
        $resultGetPages = mysql_query($queryGetPages) or die ("Query failed: error was ".mysql_error());
        return true;
    } else {
        return false;
    }
}

function incrementVisits($page,$ip) {
    $denyips = explode(" ", DENYIPS);
    if (!in_array($ip, $denyips)) {
        if (isset($page)) {
            if (checkPageExits($page)) {
                $queryIncrement = "UPDATE pagecounter3 SET visits = visits + 1 WHERE page='$page'";
                $resultIncrement = mysql_query($queryIncrement) or die ("Query failed: error was ".mysql_error());
                return true;
            } elseif(createPageEntry($page)) {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    } else {
        return false;
    }
}

switch ($a) {
default:
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");  
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header ("Pragma: no-cache"); // HTTP/1.0
header ("Content-type: image/png");
$im = @ImageCreate (30, 10)
or die ("Cannot Initialize new GD image stream");
$white = ImageColorAllocate ($im, 255, 255, 255);
$trans = imagecolortransparent($im,$white);
ImagePng ($im);
incrementVisits ($HTTP_REFERER,$REMOTE_ADDR);
break;

}
mysql_close($db);
?>
?> 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.