Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6908051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:30:43+00:00 2026-05-27T08:30:43+00:00

I am trying to create a web survey questionaire, but I don’t want same

  • 0

I am trying to create a web survey questionaire, but I don’t want same people using same ip to submit it more than once within an hour time, I am using php, I assume I need to use
$_SERVER['REMOTE_ADDR'] to get the client ip and store in the session or database and then use it to compare the new ip, I am not sure if it is right and don’t know how to exact implement this in php, can anyone help me with it, thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T08:30:44+00:00Added an answer on May 27, 2026 at 8:30 am

    When survey is submitted:

     /*
       Tracking table structure:
        `id`              INT(11) unsigned NOT NULL AUTO_INCREMENT
        `client_ip`       VARCHAR(15) NOT NULL
        `submitted_time`  DATETIME NOT NULL
     */
    
     $query = "SELECT count(`id`) AS 'count'
               FROM `tracking_table`
               WHERE 
                 `client_ip` = '".mysqli_real_escape_string($link, $_SERVER['REMOTE_ADDR'])."'
                 AND `submitted_time` > '".date('Y-m-d H:i:s',strtotime('-1 hour'))."'
               LIMIT 1";
     $result = mysqli_fetch_assoc(mysqli_query($link, $query));
    
     if ($result['count'] > 0) {
       echo "You have already submitted within the last hour";
       exit;
     }
    
     // process survey here
    
     $query = "INSERT INTO `tracking_table`
                 (`client_ip`, `submitted_time`)
               VALUES
                 ('".mysqli_real_escape_string($link, $_SERVER['REMOTE_ADDR'])."', ".date('Y-m-d H:i:s').")";
     mysqli_query($link, $query);
    

    However, you may find that this is not a good requirement – there are many valid situations where multiple users may use the same IP address (such as, for example, student accomodation). You may be preventing valid submissions by imposing this limit.

    EDIT

    Here is a basic outline of how you might do this with cookies (taking into account the limitations discussed below).

    Our cookie system works on a pair of values. ckv_1 will hold the timestamp at which the last survey was submitted. ckv_2 will hold a hash based on the timestamp and a salt, in an effort to stop people from screwing with the cookies. Obviously, if both cookies are deleted, we won’t be able to detect it, but at least this provides some sort of validation:

    function get_cookie_hash ($timestamp, $salt) {
      return md5("Extra random static string; TS: $timestamp; Salt: $salt; Extra random static string.");
    }
    
    $cookieSalt = 'Th1si54rAnd0MsTr1nG!';
    
    // If at least one of the cookies was returned, validate the request
    if (!empty($_COOKIE['ckv_1']) || !empty($_COOKIE['ckv_2'])) {
    
      $valid = FALSE;
    
      do { // Wrapped in a do-while to allow us to break out easily
        // Make sure both value are set
        if (empty($_COOKIE['ckv_1']) || empty($_COOKIE['ckv_2'])) break;
        // Get old timestamp as integer
        $oldTS = hexdec($_COOKIE['ckv_1']);
        // Make sure timestamp is more than one hour old, and the hash cookie matches it
        if ($oldTS > (time() - 3600) || $_COOKIE['ckv_2'] != get_cookie_hash($oldTS, $cookieSalt)) break;
        // OK if you get here
        $valid = TRUE;
      } while (FALSE);
    
      if (!$valid) {
        echo "Sorry - you cannot submit a survey more than once in an hour.";
        exit;
      }
    
    }
    
    // process survey here
    
    // Set the tracking cookies after processing (but before any output!)
    // We'll set them as HTTP only to help prevent XSS-type attacks
    $cookieTime = time();
    setcookie('ckv_1', dechex($cookieTime), 7200, '', '', FALSE, TRUE);
    setcookie('ckv_2', get_cookie_hash($cookieTime, $cookieSalt), 7200, '', '', FALSE, TRUE);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a web page using CSS (Table less) but my
I'm trying to create a web application using maven, tomcat and hibernate. Now I'm
I am trying to create a web application using the MVC design pattern. For
I'm trying to create a multiaction web controller using Spring annotations. This controller will
I am trying to create a web page using php. The problem is that
I'm trying to create a web service client using CXF to consume a WCF
I'm trying to create a web service using Azure. For the time being, everything
I am trying to create a web application where designers can submit and share
I am trying to create a sort of bootstrap web service using a classic
I am trying to create a php web service using nusoap lib. My code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.