FreeRpgSpot Posted January 3, 2010 Posted January 3, 2010 How would you make it so some one can enter a form into the site using their IP? Would appreciate if some one helped and made it simple. Quote
seanybob Posted January 3, 2010 Posted January 3, 2010 I'm afraid your question is too vague; please try and re-word it. Anyone can enter a form into a site, and will be using their IP to do so (unless they have some kind of proxy set up). If you're asking how to store the contents a user submit from a form using their IP as a sort of user-system, that's different. Quote
Shame Posted January 3, 2010 Posted January 3, 2010 I would like to make it so that I can store their IP into a database or something along those lines and then make it so they can only submit the form once per hour. Help me out a bit? Quote
cody4camp Posted January 4, 2010 Posted January 4, 2010 use a cron job hourly that truncates a table call IsClicked(or something) and if it is > 0 then die the session, if its less let them enter?? Is that what you want? Quote
Magictallguy Posted January 4, 2010 Posted January 4, 2010 Assuming you already have a database connection (and database).. Untested [mysql]CREATE TABLE `your_table` ( `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY, `name` VARCHAR( 50 ) NOT NULL DEFAULT 'n/a', `message` TEXT NOT NULL, `ip` VARCHAR( 20) NOT NULL DEFAULT '127.0.0.1', `time` INT( 11 ) NOT NULL DEFAULT 0 ) ENGINE = MyISAM;[/mysql] $IP = isset($_SERVER['REMOTE_ADDR']) ? mysql_real_escape_string($_SERVER['REMOTE_ADDR'], $connection_identifier) : '127.0.0.1'; if(!isset($_POST['msg'])) { $select = sprintf("SELECT `time` FROM `your_table` WHERE (`ip` = '%s')", $IP); $query = mysql_query($select, $connection_identifier) or die("Could not execute query: ".mysql_error()); if(mysql_num_rows($query)) { $row = mysql_fetch_assoc($query); if($row['time'] < time() - 3600) { echo "You have already posted a comment within the last hour. Please wait for ".date('i:s', time() - $row['time'])." before attempting to post again"; //Page footer. exit; } } echo "<form action='comments.php' method='post'>"; echo "<table width='50%' style='text-align:center;'>"; echo "<tr>"; echo "<th>Your name</th>"; echo "<td><input type='text' name='name' /></td>"; echo "</tr>"; echo "<tr>"; echo "<th>Message</th>"; echo "<td><textarea name='msg' rows='10' cols='50'></textarea></td>"; echo "</tr>"; echo "<tr>"; echo "<td colspan='2'><input type='submit' value='Submit' /></td>"; echo "</tr>"; echo "</table>"; echo "</form>"; } else { if(empty($_POST['name'])) { echo "You didn't enter your name"; //Insert page footer here exit; } if(empty($_POST['msg'])) { echo "You didn't enter a message"; //Page footer.. exit; } $_POST['name'] = mysql_real_escape_string($_POST['name'], $connection_identifier); $_POST['msg'] = mysql_real_escape_string($_POST['msg'], $connection_identifier); $query = sprintf("INSERT INTO `your_table` VALUES ('', '%s', '%s', '%s', %u)", $_POST['name'], $_POST['msg'], $IP, time()); mysql_query($query, $connection_identifier) or die("Could not execute query: ".mysql_error()); echo "Your comment has been submitted"; } Be sure to use htmlspecialchars() when outputting from the database. Use stripslashes() if you get backslashes (\) before speech marks and apostrophies Quote
Guest Null Posted January 13, 2010 Posted January 13, 2010 Itd be alot better if you just did it by userid's. I mean ppl can create multiple accounts, but then again, if u did it by ip, it would make it easier for them considering using a proxy can still post before an hour Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.