Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ok, one way to do this is to check the message before it's even been added to the chat file. A easy way to accomplish this with PHP is to use PHP Sessions that will store a counter for repeated values. Since I don't know the structure of your site, I'll give you basic instructions of how to do this: <br/></p> <p><strong>1. Start the session for the "post to chat" function</strong><br/> PHP Sessions need to be started wherever you use them. This can be done with a simple. <br/></p> <pre><code>session_start(); </code></pre> <p><strong>2. Create the two session variables if it doesn't exist</strong></p> <pre><code>session_start(); if(!isset($_SESSION['latest_link'])){ //isset() checks whether or not the variable exists $_SESSION['latest_link'] = ""; } if(!isset($_SESSION['duplicate_count'])){ $_SESSION['duplicate_count'] = 0; } </code></pre> <p><strong>3. For new links check if it matches the last link</strong></p> <pre><code>session_start(); if(!isset($_SESSION['latest_link'])){ //isset() checks whether or not the variable exists $_SESSION['latest_link'] = ""; } if(!isset($_SESSION['duplicate_count'])){ $_SESSION['duplicate_count'] = 0; } if($_SESSION['latest_link'] == trim(strtolower($link))){ //where $link is the new link being posted. trim() removes unneeded whitespace and strtolower() makes everything lowercase. This way, the poster can't fool the system through capitalization or extra spaces } </code></pre> <p><strong>5. If the link is a duplicate add one to the <code>duplicate_count</code>.</strong></p> <pre><code>session_start(); if(!isset($_SESSION['latest_link'])){ //isset() checks whether or not the variable exists $_SESSION['latest_link'] = ""; } if(!isset($_SESSION['duplicate_count'])){ $_SESSION['duplicate_count'] = 0; } if($_SESSION['latest_link'] == trim(strtolower($link))){ //where $link is the new link being posted. trim() removes unneeded whitespace and strtolower() makes everything lowercase. This way, the poster can't fool the system through capitalization or extra spaces $_SESSION['duplicate_count']++; //add one to duplicate_count } </code></pre> <p><strong>6. Check if the <code>duplicate_count</code> is larger than 2</strong></p> <pre><code>session_start(); if(!isset($_SESSION['latest_link'])){ //isset() checks whether or not the variable exists $_SESSION['latest_link'] = ""; } if(!isset($_SESSION['duplicate_count'])){ $_SESSION['duplicate_count'] = 0; } if($_SESSION['latest_link'] == trim(strtolower($link))){ //where $link is the new link being posted. trim() removes unneeded whitespace and strtolower() makes everything lowercase. This way, the poster can't fool the system through capitalization or extra spaces $_SESSION['duplicate_count']++; //add one to duplicate_count } if($_SESSION['duplicate_count'] &gt; 2){ //user has posted same link more than 2 times. Action should be taken. } </code></pre> <p><strong>7. Log the user's latest link if it is different, and reset the counter</strong> <br/> Simply done with</p> <pre><code>session_start(); if(!isset($_SESSION['latest_link'])){ //isset() checks whether or not the variable exists $_SESSION['latest_link'] = ""; } if(!isset($_SESSION['duplicate_count'])){ $_SESSION['duplicate_count'] = 0; } if($_SESSION['latest_link'] == trim(strtolower($link))){ //where $link is the new link being posted. trim() removes unneeded whitespace and strtolower() makes everything lowercase. This way, the poster can't fool the system through capitalization or extra spaces $_SESSION['duplicate_count']++; //add one to duplicate_count }else{ $_SESSION['latest_link'] = trim(strtolower($link)); $_SESSION['duplicate_count'] = 0; } if($_SESSION['duplicate_count'] &gt; 2){ //user has posted same link more than 2 times. Action should be taken. } </code></pre> <p>Of course, you should also consider securing your sessions to prevent <code>session hijacking</code>, but that is another topic that you can find plenty of answers for on Stack Overflow. This post has some good pointers: <a href="https://stackoverflow.com/questions/328/php-session-security">PHP Session Security</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload