如何不刷新增加页面/帖子查看次数?

时间:2015-11-20 06:06:35

标签: php

我已经在线搜索了一种禁用帖子/页面浏览的方法" hacking"有令人耳目一新的页面,但我找不到任何。

如何在刷新时不增加页面/帖子后的数量?

或来自不同角度的同一问题:

如何仅注册唯一身份访问?

我目前的想法是IPnonce,但我担心我需要一些帮助才能开始。

目前的代码非常简单:

    /* Allow devs to override the meta key used. By default, this is 'Views'. */
    $meta_key = 'estate_property_views_count';

    /* Get the number of views the post currently has. */
    $old_views = get_post_meta( $post_id, $meta_key, true );

    /* Add +1 to the number of current views. */
    $new_views = absint( $old_views ) + 1;

    /* Update the view count with the new view count. */
    update_post_meta( $post_id, $meta_key, $new_views, $old_views );

1 个答案:

答案 0 :(得分:2)

方法1 - 使用Cookie:

您可以使用Cookie来代替IP。您需要先检查cookie是否存在,如果不存在则更新并设置cookie,否则不要。

这样的事情会起作用:

- (IBAction)nextTipAction:(id)sender
{
    NextTipNumber++;  // Assume that on didload it initiate to 1 and also load on view didload you have load first tip.

    [ProgressHUD show:@"Loading Next Tip"];
    //Get Current Comments//

    __weak typeof (self) weakSelf = self;

    PFQuery *query = [PFQuery queryWithClassName:@"Archive"];
    [query orderByAscending:@"tipNumber"];
    [query setLimit: NextTipNumber];   // Set the limit according which tip you want to access
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (!error)
        {
            PFObject *ArchiveObject = [objects lastObject];
            weakSelf.tipNumberLabel.text = [ArchiveObject objectForKey:@"tipNumber"];
            weakSelf.tipBody.text = [ArchiveObject objectForKey:@"body"];

            [ProgressHUD dismiss];
        }
        else
        {
            [ProgressHUD dismiss];
            [ProgressHUD showError:@"Sorry! Unable to load Tips"];
            // Log details of the failure
            NSLog(@"Error: %@ %@", error, [error userInfo]);
        }
    }];
}

方法2 - 使用会话

在脚本的第一行添加if(!isset($_COOKIE['not_unique'])) { setcookie('not_unique', '1', time() + (86400 * 30)); //30 days $old_views = get_post_meta( $post_id, $meta_key, true ); $new_views = absint( $old_views ) + 1; update_post_meta( $post_id, $meta_key, $new_views, $old_views ); } ,然后像这样使用它:

session_start();