1 (edited by 2012-03-15 08:11:11)

Topic: problem expanding Counter Hack

I implemented the Counter Hack (https://cutephp.com/forum/index.php?showtopic=33202) and it is working fine!
Now I am trying to expand this with a like-feature.

For this reason I changed (shows.inc.php):
- expanded the form with a like checkbox (CNLike) $CNLike is filled with 1 when checked (works)
- changed validations for name and comment (no name or comment needed when like=true) (works)
- implemented skip adding comment when only like=1  (works)
- str_replace {likes} 2x so it ca be used in templates (works)

and changed (counter.php):

$counter = array();
foreach(file($file_path) as $line_num => $line){
    $line = explode("|",$line);
    $counter[$line[0]] = array("views"=>0,"unique views"=>0,"online"=>0,"likes"=>0);
    if($line[1]!="")
        foreach(explode(" ",$line[1]) as $part_num => $part){
            $part = explode(":",$part);
            if($part[3]>=($time-$online_timeout))$counter[$line[0]]["online"] += 1;
            $counter[$line[0]]["views"] += $part[1];
            $counter[$line[0]][$part[0]] = array($part[1],$part[2],$part[3],$part[4]);
            $counter[$line[0]]["unique views"] += 1;
            $counter[$line[0]]["likes"] += $part[4];        }
}

if($cn_do=="update"){
    // update or write this users stats
    if(is_array($counter[$id])){
        if(is_array($counter[$id][$ip])){
            $counter[$id][$ip][0] += 1;
            $counter[$id]["views"] += 1;
            $counter[$id][$ip][2] = $time;
            $counter[$id][$ip][3] = $counter[$id][$ip][3] + $CNlike;
        }
        else{
            $counter[$id][$ip] = array(1,$time,$time);
            $counter[$id]["unique views"] += 1;
            $counter[$id][$ip][3] = $CNlike;        }
    }
    elseif(is_numeric($id))$counter[$id] = array("views"=>1,"unique views"=>1,"online"=>0,"likes"=>0,$ip=>array(1,$time,$time));

For some reason             $counter[$id][$ip][3] = $counter[$id][$ip][3] + $CNlike; is always filled with zero,
I cannot understand why because its filled earlier in the (shows.inc.php) script.

The contents of counter.txt looks OK:
1331533124|172.30.32.19:43:1331793164:1331796594:0|

The display part works (Likes are displayed when i fill them manually in counter.txt), but the filling somehow doesn't work.
I'm just a PHP-starter so can anybody help me?

2 (edited by 2012-03-15 09:55:42)

Re: problem expanding Counter Hack

Whats the content of
$counter[$id][$ip][3]

Re: problem expanding Counter Hack

Whats the content of
$counter[$id][$ip][3]


The number of likes per IP per article filled by the checkbox (added to the form)

Re: problem expanding Counter Hack

$CNLike or  $CNlike ?

Re: problem expanding Counter Hack

$CNLike or  $CNlike ?


Thats not the problem. Its somewhere where the formdata is actually posted $CNLike gets empty.

echo "<script type=\"text/javascript\">window.location=\"$PHP_SELF?subaction=showfull&id=$id&ucat=$ucat&archive=$archive&start_from=$start_from&$user_query;</script>";