Please login or register. Welcome to the Studio, guest!


Quick Links:


newBookmarkLockedFalling

Llanilek

Llanilek Avatar
Former Elite Mod

****
Dedicated Studio Member

931


October 2005
before you post your form into a mysql database, you can disable html using the following functions

$iPost = @$_POST['post'];
$iPost = htmlspecialchars($iPost);
$iPost = nl2br($iPost);

that way, it parses line breaks, but turns stuff like > into & gt ;


Last Edit: Mar 7, 2006 13:17:53 GMT by Llanilek

crazynarutard

crazynarutard Avatar

*****
Senior Studio Member

1,470


August 2005
or: htmlentities($_POST['post'],ENT_QUOTES);

Adding a "addslashes" function with it is also a good idea, all of this is usuaully to prevent mysql injection attacks.
There is also mysql_real_escape_string, but that can only be used when a mysql connection has been established.

Llanilek

Llanilek Avatar
Former Elite Mod

****
Dedicated Studio Member

931


October 2005
yeh... sql injection sucks.. really badly... thanks for pointing them things out CJ :)

Singular

Singular Avatar
v4 Studios :: Coming Soon

***
Dedicated Member

238


September 2005
That is what I had to use for my shoutboxes.
Further Solutions :: Hosting :: Scripts :: Templates
furthersolutions.com

v4 Studios - Coming soon

Llanilek

Llanilek Avatar
Former Elite Mod

****
Dedicated Studio Member

931


October 2005
another quick tip is to use all of them, bt make it into your own function.. something like thie



<?php

function keepSafe($iPost) {

$iPost = htmlspecialchars($iPost); // strip all html chars from the string
$iPost = addslashes($iPost); // escape all unescaped quotes.
$iPost = mysql_real_escape_string($iPost); // optional if you don't use add slashes.
$iPost = nl2br($iPost);

return $iPost;
}

?>


simple security checks like this can stop holes appearing in your scripts,

i always try to encourage good coding practices when it comes to security.. check, double and triple check your scripts before you upload them to a live server... if needed, find a CEH (Certified Ethical Hacker) or "White Hat" to check through your script if you know someone you trust to do this


Last Edit: Aug 29, 2006 15:50:32 GMT by Llanilek

Chris

Chris Avatar

******
Head Coder

19,519


June 2005
Bad idea. addslashes and mysql_real_escape_string don't mix. :P

Also, I think you forgot the return....

Llanilek

Llanilek Avatar
Former Elite Mod

****
Dedicated Studio Member

931


October 2005
cddude229 said:
Bad idea. addslashes and mysql_real_escape_string don't mix. :P

Also, I think you forgot the return....



which is why i didn't add the comment for real escape... it is optional.

as for the return.. well spotted *adds*

newBookmarkLockedFalling