473,385 Members | 1,521 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

PHP & mySQL - limit user posting

118 100+
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($sql) 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 1705
helraizer1
118 100+
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
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...
0
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...
6
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...
1
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,...
2
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...
0
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...
0
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...
6
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...
1
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.