Refactor
:my
=>
'code'
Codes
Refactorings
Popular
Best
Submit
Spam
Account
Logout
Login
JavaScript doesn't seem to be activated, expect things to be ugly and sloppy!
Learn How to Create Your Own Programming Language
createyourproglang.com
Recent
Simple Particle Engine for a shooter game
Snake / Nibbles clone in C and Ncurses
Please improve
Parsing of XML data has high CPU usage
Convert simple Javascript to jQuery plugin
Active Record getting unique records
List the files in a directory without the directory name or the extension
clean the code
ohs system, recruitment software, hr software, oh&s software, human resources software, ohs software
Array parsing in a block
Popular
Parsing of XML data has high CPU usage
Please improve
Snake / Nibbles clone in C and Ncurses
List the files in a directory without the directory name or the extension
Convert simple Javascript to jQuery plugin
Simple Particle Engine for a shooter game
Active Record getting unique records
Breadth first cartesian product iterator
php refactoring
first BST
Pastable version of
Message system IP-ban
<pre class='prettyprint' language='php'><?php $host = "host"; $user = "user"; $pass = "password"; $db = "database"; mysql_connect($host,$user,$pass); mysql_select_db($db); ?> <!-- HTML part for the form--> <form method="post"> <table> <tr> <td align=left> Name: </td><td><input type="text" name="naam" size="20" maxlength="20"></td> </tr> <tr> <td align=left> Message: </td><td><input type="text" name="bericht" size="100" maxlength="100"></td> </tr> <tr> <td><input class="button" type="submit" name="submit" value="Add it!"></td> </tr> </table> </form> <? $banned_ips = array('127.0.0.1','255.255.255.0','localhost'); // Determine the poster's IP address function getip() { if(isset($_SERVER['HTTP_CLIENT_IP'])) { $ip = $_SERVER['HTTP_CLIENT_IP']; } else { if(getenv('HTTP_X_FORWARDED_FOR')) { $ip = getenv('REMOTE_ADDR'); if(preg_match("/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/", getenv('HTTP_X_FORWARDED_FOR'), $ip3)) { $ip2 = array('/^0\./', '/^127\.0\.0\.1/', '/^192\.168\..*/', '/^172\.16\..*/', '/^10..*/', '/^224..*/', '/^240..*/'); $ip = preg_replace($ip2, $ip, $ip3[1]); } } else { $ip = getenv('REMOTE_ADDR'); } if($ip == "") $ip = "x.x.x.x"; } return $ip; } $IPbezoeker = getip(); $tijd = date("d/m/y - H:i:s"); $tijd2 = time(); $naam = $_POST['naam']; $bericht = $_POST['bericht']; if(isset($_POST['submit'])){ if (in_array("$IPbezoeker",$banned_ips)){ $ip_check = "true"; } else { if (!(in_array("$IPbezoeker",$banned_ips))){ $ip_check = "false"; }} if($ip_check = "false"){ mysql_query ("INSERT INTO berichten (naam, bericht, ip, tijd, tijd2) VALUES ('$naam','$bericht','$IPbezoeker','$tijd','$tijd2')"); echo "<table>The message was successfully added! Sending you back to the frontpage now...</table>"; echo "<meta http-equiv='Refresh' content='2; url=index.php'>"; echo "Your ip is $IPbezoeker"; } else { if(isset($_POST['submit']) AND $ip_check = "true"){ echo "Sorry, but you can't post messages anymore. You have been banned for misuse of the system!"; echo "Your ip is $IPbezoeker"; }}} mysql_close(); ?></pre> <a href="http://www.refactormycode.com/codes/132-message-system-ip-ban" style="color:#fff" title="As seen on RefactorMyCode.com"><img alt="Small_logo" src="http://www.refactormycode.com/images/small_logo.gif" style="border:0" /></a>