473,830 Members | 2,085 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP & mySQL - limit user posting

118 New Member
Hi folks,

In my script I have this code:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. unset($errors);
  4.  
  5. include ("linesfile.php5");
  6. $filename = "data.line";
  7. set_magic_quotes_runtime(0);
  8.  
  9. if ($_POST['submit'] && strlen($_POST['input']) < 5) {
  10.     $errors[] .= _NO_5;
  11. }
  12. if ($_POST['submit'] && strlen($_POST['username']) < 3) {
  13.     $errors[] .= _NO_2;
  14. }
  15. $dirty = array('rude word', 'another rude word', 'etc');
  16.  
  17. foreach($dirty AS $bad_word){
  18.           if(preg_match("/$bad_word/i", $_POST['input'])) $errors[]= 'The word you entered, "'.$bad_word.'", has been detected as being offensive; your post has not been submitted. Sorry for any inconvenience.';
  19.           }
  20.  
  21.  
  22.  
  23.  
  24. ?>
  25.               <div class="ddgb_entrybox">
  26.         <table width="100%" border="0" cellspacing="8" cellpadding="0">
  27.         <tr>
  28.         <td width="42%" align="center" valign="top"></td>
  29.         <td align="left" valign="top">
  30. <?php
  31.  
  32. if (isset($_POST['submit']) && $errors[0] != null) {
  33.     echo "<h2>" . _ERROR . "</h2><ul>";
  34.     foreach ($errors as $f) {
  35.         echo "<li>" . $f . "</li>";
  36.     }
  37.     echo "</ul>";
  38. } elseif ($_POST['submit']) {
  39.     // grab the inputted text
  40.     $text = htmlspecialchars(stripcslashes($_POST['input'] . "\n"));
  41.     $username = htmlspecialchars(stripslashes($_POST['username']));
  42.     $color = $_POST['color'];
  43.     $font = $_POST['font'];
  44.     $ip = $_SERVER['REMOTE_ADDR'] . "\n";
  45.     $ip1 = $_SERVER['REMOTE_ADDR'];
  46.     $time = time();
  47.     $_SESSION['username'] = $username;
  48.     $_SESSION['color'] = $color;
  49.  
  50.  
  51.     $data[] = "\n" . htmlspecialchars_decode(substr($username, 0, 10));
  52.     $data[] = trim($color);
  53.     $data[] = trim($font);
  54.     $data[] = htmlspecialchars_decode(trim(substr($text, 0, 75)));
  55.  
  56.  
  57.  
  58.  
  59.   //Process the post
  60.  
  61.     $datafile = new DataFile($filename);
  62.     if (!$datafile->writeNewLine($data))
  63.         die("Error writing to file");
  64.  
  65. }
  66.  
  67. ?>
  68.  
I have a database set up called `chatbox` with a table `post` having the fields 'time' and 'ip'.

The idea: when the user posts, their ip is stored in the database along with the time stamp from when they post using

[php]$sql = "INSERT INTO `chatbox`.`post ` (`time`, `ip`) VALUES ('$time, $ip)"; //$time being merely time() and $ip being $_SERVER['REMOTE_ADDR'];

$result = mysql_query($sq l) or die('Error in SQL: ".mysql_error() );
[/php]

I was planning to then query the database to see whether that ip (user) posted within the last 30 seconds ( if($row['time'] < ($time + 30)) { } ) if they have then $errors[] = 'You have already posted once, please wait 30 seconds to post again'; if not then it will post the form.

I have the code to use but how would I impliment this into my code?

Thanks,
Sam
Feb 5 '08 #1
1 1734
helraizer1
118 New Member
I've managed to come up with a solution.

Sam
Feb 6 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
3282
by: Jay Moore | last post by:
Greetings, all! I have a project for work, and I'm not sure how to efficiently do what I need to do. I'm hoping someone out there can help. Project is this: I'm creating a web-based interface where people at my company (operators) can enter data for service calls. All data entered is run thru one or more PHP scripts for error checking and then stored in a MySQL database on a server here in the office.
0
3955
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated: Mon Jun 7 10:37:28 EDT 2004 The latest version of this document can be found at: http://prdownloads.sourceforge.net/souptonuts/README_mysql.txt?download
6
3192
by: Erik H. | last post by:
Trying to connect to MySQL db on localhost, and populate datagrid from a dataset using code inline method. Getting the following compile error: Error Message: "CS0246: The type or namespace name 'CoreLab' could not be found (are you missing a using directive or an assembly reference?)" I downloaded the add on for connecting to MySQL using ADO.NET and installed it, but am still getting this error. Anybody ever run into this before?
1
3028
by: SC | last post by:
I'm developing a site that may eventually have a very large database of users (hopefully, but who knows). It will be a community website where users can search each other (think Friendster, Classmates, every dating site out there, etc.). Often there will be queries with multiple joins and sometimes may include a few fulltext searches. Each page of results will have a limited number of results displayed (obviously). As I understand it,...
2
2618
by: mattdfong | last post by:
I am using mysql to receive stock market rate data, and I have a rate feed which tells me when the rate has changed. I input the data as it comes in, into a mysql database that has both a unix_timestamp() field and the rate field. Neither field is indexed. What I need to do is calculate the Moving Average by taking the rate from 30 seconds, 60, 90, etc seconds ago. Currently I am using the humungous sub query select statement below. Are...
0
5578
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted ******************************************************** For this teeny job, please refer to: http://feeds.reddit.com/feed/8fu/?o=25
0
6694
by: Chrom_ | last post by:
Mysql is filling my /var partition because the log limit doesn't seem to be respected. I've tried many different settings in /etc/mysql/my.cnf but nothing works. Logrotate is not enabled/configured. I just want mysql to use a maximum of, let's say, 1GB of my /var partition The log is /var/log/mysql/
6
38536
Atli
by: Atli | last post by:
This is an easy to digest 12 step guide on basics of using MySQL. It's a great refresher for those who need it and it work's great for first time MySQL users. Anyone should be able to get through this without much trouble. Programming knowledge is not required. Index What is SQL? Why MySQL? Installing MySQL. Using the MySQL command line interface
1
2419
by: chanshaw | last post by:
Alright so I got php running and installed i have mysql running and installed the thing im having a hard time with is having the php to call information from the mysql database. Im on Windows Vista Ultimate, I'm using iis7 here is the code of the php. <?php $Username = "Webuser"; $Password = "password"; $Database = "sample"; $Hostname = "localhost"; $MySQLConnection = mysql_connect($Hostname, $Username, $Password) ...
0
9793
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10526
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9315
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7747
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6951
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5617
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5780
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4416
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3076
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.