$sql = "DELETE FROM " . UNIQUE_HITS_TABLE . "
WHERE hits_ip = '$hits_ip'";
if (!$result = $db->sql_query($sql))
{
error_message(GENERAL_ERROR, "Couldn't delete unique hit", "", __LINE__, __FILE__, $sql);
}
// it's possible something like this
// could be replaced with:
// $result = $db->sql_query($sql) or error_message(GENERAL_ERROR, "Couldn't delete unique hit", "", __LINE__, __FILE__, $sql);
}
$set_2 = $user_ip == $hit['hits_ip'] ? 0 : 1;
}
Amailer
Posted: Fri Mar 12, 2004 10:20 pm Post subject: (No subject)
see the problem now is
code:
$set_2 = $user_ip == $hit['hits_ip'] ? 1 : 0;
the $user_ip is getting repeated for every record in the database :S
so.. it's basicallt the same thing
wtd
Posted: Fri Mar 12, 2004 10:36 pm Post subject: (No subject)
That's because you don't change $user_ip in the loop.
Amailer
Posted: Fri Mar 12, 2004 10:45 pm Post subject: (No subject)
errr, yes-- and the way to fix this is?
wtd
Posted: Fri Mar 12, 2004 11:07 pm Post subject: (No subject)
Somewhere inside your loop put:
code:
$user_ip = something
The something depends on what kind of information you want to store in $user_ip.
Amailer
Posted: Sat Mar 13, 2004 10:15 am Post subject: (No subject)
no no no no, user_ip is already set -.- *duh*,
it's the encoded ip address of the user viisting the page-- but the script wrong woth because if you see... it' keeps duplicating the user_ip
(ie c0394101c0394101c0394101c0394101c0394101c0394101c0394101 )
that means the if statement does not work--- because there is never going to be such a long ip in the database (cuz it get's repeated for every record in the db...)
that's the first problem it's self :S
btw,
there is an if statement saying
if ($set_2 == 1) {
do bla
but because of this problem, the $set_2 is always 1 !!!!
Amailer
Posted: Sun Mar 14, 2004 8:52 am Post subject: (No subject)
OKAY.
Well i did solve the problem this way
code:
//
// Here we are going to get/set the site's unique hits
// (also delete them if they are older then a week).
//
$page = $_SERVER["REQUEST_URI"]; // get the page the user is at
if ($page == '/') {
$page = 'index.php'; // The page
} //
$page = str_replace("/", "", $page); // ^
$sql = "SELECT * FROM " . UNIQUE_HITS_TABLE . " WHERE hits_ip='$user_ip'";
if (!$result = $db->sql_query($sql)) {
error_message(GENERAL_ERROR, "Couldn't get unique hits information", "", __LINE__, __FILE__, $sql);
}
$sql = "DELETE FROM " . UNIQUE_HITS_TABLE . "
WHERE hits_ip = '$hits_ip'";
if (!$result = $db->sql_query($sql))
{
error_message(GENERAL_ERROR, "Couldn't delete unique hits", "", __LINE__, __FILE__, $sql);
}
// it's possible something like this
// could be replaced with:
// $result = $db->sql_query($sql) or error_message(GENERAL_ERROR, "Couldn't delete unique hit", "", __LINE__, __FILE__, $sql);
}
}
but i don't like that way :S so anyone know another way TELL me
Sponsor Sponsor
wtd
Posted: Sun Mar 14, 2004 10:09 am Post subject: (No subject)
PHP makes me want to turn into the Hulk and smash things. Since everything is dependent on global variables, it's very hard to help you without seeing all of the code.
Amailer
Posted: Sun Mar 14, 2004 11:02 am Post subject: (No subject)
code:
$user_ip = 'c0101010';
//
// Here we are going to get/set the site's unique hits
// (also delete them if they are older then a week).
//
$page = $_SERVER["REQUEST_URI"]; // get the page the user is at
if ($page == '/') {
$page = 'index.php'; // The page
} //
$page = str_replace("/", "", $page); // ^
$sql = "SELECT * FROM " . UNIQUE_HITS_TABLE . " WHERE hits_ip='$user_ip'";
if (!$result = $db->sql_query($sql)) {
error_message(GENERAL_ERROR, "Couldn't get unique hits information", "", __LINE__, __FILE__, $sql);
}
//
// Now to check if the IP has been in the database for the past week
// if it is delete it from the database (this is because this counter counts the ips for the past week)
//
if (($hit['hits_time'] * (60 * 60 * 24 * 7)) <= time())
{
$hits_ip = $hit['hits_ip'];
$sql = "DELETE FROM " . UNIQUE_HITS_TABLE . "
WHERE hits_ip = '$hits_ip'";
if (!$result = $db->sql_query($sql))
{
error_message(GENERAL_ERROR, "Couldn't delete unique hits", "", __LINE__, __FILE__, $sql);
}
}
}
$cookiename = 'gfxpro_'; // Cookie name for the sites cookies ;D
if (!isset($HTTP_COOKIE_VARS[$cookiename . 'unique'])) {
if ($set_2 == 1) {
$time = time();
Posted: Wed Mar 17, 2004 4:53 am Post subject: (No subject)
yo i remember i used to have some code like that in my old website for downloads or something....
here's how it was:
i had a row for every download file...
everytime an ip would try downloading them it would check the existing ips and if they were'nt there it would just add it to the ip string in my database...
here's how the ip string worked:
ipÞipÞipÞipÞip ie 24.24.65.78Þ54.698.32.12Þ01.54.38.65Þ
i just used Þ for separator... and it worked perfectly fine...
so u might wanna give that a try...
Amailer
Posted: Wed Mar 17, 2004 9:15 am Post subject: (No subject)
I fixed the unique hits problem but you gave me an idea for my download module... insted of using cookies i can do that,
thanks ;D
Homer_simpson
Posted: Thu Mar 18, 2004 3:14 am Post subject: (No subject)
netime...
if u need i could send u source code for my whole website...
it had some code parts that might come to use...
Amailer
Posted: Thu Mar 18, 2004 8:51 am Post subject: (No subject)
sure, why not
Homer_simpson
Posted: Thu Mar 18, 2004 2:14 pm Post subject: (No subject)