Location: PHPKode > scripts > Page Views > gsg_pv_count.php
<?php

include('gsg_pv_config.php');

function curPageURL() {
 $pageURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 } else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
 return $pageURL;
}

function gsg_pv_count_this_page() {

$url = curPageURL();

$query = "SELECT * FROM gsg_pv_table WHERE url='$url'";
$result = mysql_query($query);
$row = mysql_fetch_array( $result );

$url2 = $row['url'];

if ($url == $url2) {

$views = $row['views'];
$views++;

$query = "UPDATE gsg_pv_table SET views='$views' WHERE url='$url'";
mysql_query($query);

}
else {

$insert_query = "INSERT INTO gsg_pv_table (views, url) VALUES ('1', '$url')";
mysql_query( $insert_query );

}

}

gsg_pv_count_this_page();

mysql_close($gsg_pv);

?>
Return current item: Page Views