Jump to content
php.lv forumi

Paradat piemeru Online + Location


GeRik

Recommended Posts

Pienemsim ja man ir datubaze

ar shadiem laukiem

id un kodara

un ja lietotajs atrodas pienemsim Galvenaja lapa

piemeram localhost/index.php

Un ja tas butu ierakstits tabula ka id 0 un pie kodara Lasa Jaunumus (uzraksts)

ka man to izpildit lai uzraditu ? ja sapratat ko es domaju

Link to comment
Share on other sites

Ja gribi, lai ierakstās datu bāzē visi linki, kas ir spiesti, tad paskaties, kā taisa vienkāršu HIT COUNTER, tad arī sapratīsi, kā to dabūt gatavu. Ja pareizi atceros, lai noteiktu, kāds skripts šobrīd strādā iekš PHP to varēja izdarīt ar $_SERVER['SCRIPT_NAME'].

Link to comment
Share on other sites

<?$type = 1;

//Function to get user ip (stolen from phpskills.com :)
function get_user_ip(){       
$ipParts = explode(".", $_SERVER['REMOTE_ADDR']);
if ($ipParts[0] == "165" && $ipParts[1] == "21") {    
   	if (getenv("HTTP_CLIENT_IP")) {
       	$ip = getenv("HTTP_CLIENT_IP");
       } elseif (getenv("HTTP_X_FORWARDED_FOR")) {
           $ip = getenv("HTTP_X_FORWARDED_FOR");
       } elseif (getenv("REMOTE_ADDR")) {
           $ip = getenv("REMOTE_ADDR");
       }
   } else {
      return $_SERVER['REMOTE_ADDR'];
  	}
  	return $ip;
}

// Use this to check that the ip was already entered into the database (no entry is made)
$match = false;
$user_ip = get_user_ip();
$get_user = @mysql_query("SELECT * FROM ips WHERE `ip`='$user_ip'");

if(@mysql_num_rows($get_user) > 0){
$match = true;
} else {
$insert_ip = @mysql_query("INSERT  INTO ips (`ip`) VALUES ('$user_ip')");
}	

// Check Type Kind		
if($type == 2 || ($type == 1 && $match == false)){
$get_last_hit = @mysql_fetch_array(@mysql_query("SELECT * FROM myhits WHERE `name`='frontpage'"));
$get_last_hit[1]++;

$update_count = @mysql_query("UPDATE myhits SET hits='$get_last_hit[1]' WHERE name='frontpage'");
} else {
$get_last_hit = @mysql_fetch_array(@mysql_query("SELECT * FROM myhits WHERE `name`='frontpage'"));
}

// It is safe to change these information to your needs
if($type == 2){
echo 'Page\'s Total hits: ' . $get_last_hit[1];
} else {
echo 'This Page Has: ' . $get_last_hit[1] . ' Unique hits!';
}
?>

Apskatijos sho te bet vari ieteikt ar ko sakt izmainit un ko nodzest

Edited by GeRik
Link to comment
Share on other sites

manai lapelei arī kas tāds ir.. :)

ja ir lietotājs ielogojies, tad man ieraksta db vinju un vinja atrasanās vietu.. tad es uzaisīju funkciju, kas atrod linkā lapusi un tadattiecīgi nosaukumu ierakstu.. tādējādi man rādās atrašanās vieta.:)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...