vendredi 28 juin 2019

Laravel-Visitors Counter

this code repeats one IP hits every time when I visit this IP... if I visit repeatedly with one IP hits increment, not IP increment

how can I solve this ?? can anyone guide?

   $date = new \DateTime;

    $check_if_exists = DB::table('visitors')
    ->where('ip',$_SERVER['REMOTE_ADDR'])->first();

    $get_visit_day = DB::table('visitors')->select('created_at')
    ->where('ip', $_SERVER['REMOTE_ADDR'])->first();

   $value = date_create($get_visit_day->created_at);
    if(!$check_if_exists)
    {
        DB::table('visitors')->insert(array('ip' => 
        $_SERVER['REMOTE_ADDR'], 'hits' => '1', 'created_at' => $date));
    }else{
        DB::table('visitors')->where('ip', $_SERVER['REMOTE_ADDR'])
        ->increment('hits')->insert('updated_at', $date);
        // DB::table('visitors')->insert('updated_at', $date);
    }

    // $value = date_create($get_visit_day->created_at);
    if ($check_if_exists && date_format($value, 'd') != date('d')) {
        DB::table('visitors')->insert(array('ip' => $_SERVER['REMOTE_ADDR'], 'hits' => '1', 'created_at' => $date));
    }[enter image description here][1]



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire