0

If I click mare that 1 time on banner my PHP function counting it, maybe are some solution to count only 1 click, or create faster redirection that user not have time to click more that 1 time ?

This is my function:

function wp125_adclick() {
    if (isset($_GET['adclick']) && $_GET['adclick'] != "" && ctype_digit($_GET['adclick'])) {
    $theid = $_GET['adclick'];
    global $wpdb;
    $adtable_name = $wpdb->prefix . "wp125_ads";
    $thead = $wpdb->get_row($wpdb->prepare(
        "SELECT target FROM {$adtable_name} WHERE id = %d",
        $theid
    ));
    $theid = $wpdb->escape($theid);
    $update = "UPDATE ". $adtable_name ." SET clicks=clicks+1 WHERE id='$theid'";
    $results = $wpdb->query( $update );
    header("Location: $thead->target");
    exit;
    }
}

1 Answer 1

2

You could use a session variable to count the clicks. So you can avoid to count multiple clicks.

if(!isset($_SESSION['click_already_saved'])) {
    $update = "UPDATE ". $adtable_name ." SET clicks=clicks+1 WHERE id='$theid'";
    $results = $wpdb->query( $update );
    $_SESSION['click_already_saved']=true;
}
Sign up to request clarification or add additional context in comments.

1 Comment

If I guess correctly you use wordpress. WordPress will do that for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.