As said above, for integers (or floats) simply typecast into int (or float) without thinking.
For strings, you have two types of attacks that you need to solve for:
SQL injection - this is accomplished by smart pre-escaping of your escaping of slashes. Addslashes() has proven weak. mysql_real_scape_string() is much stronger, as any engine-native escape function, but I hear it can be pre-escaped in some cases. Strongest form against SQL injection that I know is using mysqli and prepared statements, if you have access to PHP5 and Mysq4.1+.
XSS attacks (cross site scripting) - this is accomplished by injecting malicious html or scripting code into content that will be SHOWN BACK to users, especially admins. By injecting a script that collects cookies and passes through an IMG link to attacker's server, they can hijack sessions. Or they can change content of the website, generally they can do wahtever they want with (presented) content. So basically, strip tags like <script> <applet> <object> <embed> <iframe>. Also watch for urlencoded "<" and ">" chars. If you use utf-8 or any other two-byte encoding, make sure you have consistent encoding in html, database collation and wherever string manipulation is required (like escaping with slashes)
CSRF (cross site request forgeries) is biggest problem, but not solvable with input cleaning. It exploits GET protocol by forging authentication. By injecting a harmless image tage in a forum post, for example: <img src="admin.php?action=delete_content&content_id=123">, even with bbcode, your browser contacts admin.php with given GET parameters thinking it evokes an image. Admin.php will likely check session or other cookies for authentication - which are available if you're logged in as admin - and will proceed deleting the content. This is just a stretched example, but this is how CSRF works.
As for register_globals, always have that turned off.
Very good protection:
- Check input by Javascript (and dissallow form submission if invalid)
1a. Make sure form can't be sent by accident if Javascript is disabled (change action by javascript)
- Re-check input on server-side
- If invalid, means Javascript avoided, means hacking attack, ban IP automatically or do something else to protect self
I suggest reading this and the links to articles presented within:
http://www.whitehatsec.com/presentations/phishing_superbait.pdf