Our Scripts Vault contains many game scripts that you can use to create your own game!
<?phpfunction secureInput($string) { $string = strip_tags($string); $string = htmlspecialchars($string); $string = trim($string); $string = stripslashes($string); $string = mysql_real_escape_string($string); return $string;}?>
Here's a little function i use ....Code: [Select]<?phpfunction secureInput($string) { $string = strip_tags($string); $string = htmlspecialchars($string); $string = trim($string); $string = stripslashes($string); $string = mysql_real_escape_string($string); return $string;}?>
- SQL injection, always pass strings through mysql_real_escape_string()- SQL injection, make sure all numbers are numbers; (int) conversion or '$var'.- check for negative values in formsThe 3 above are enough (except for user provided content since this is a bit more tricky). For user generated content just strip all html tags and do not allow images, you can enalble them later once you learn how these works.
SQL injection, make sure all numbers are numbers; (int) conversion or '$var'.
if (!is_numeric ($someVar) || intval ($someVar) < 0){ throw new ErrorException ('Why do I see this message? Should I be logging your activity to report as a hacking incident?', 0, E_ERROR, __FILE__, __LINE__);}
I have a hard time understanding why so much effort is taken to 'clean' data for security measures. Instead, why not 'validate' the data and return an error if it is invalid?For instance, instead of forcing data to be an unsigned integer, why don't you validate that it's an unsigned integer?Code: (php) [Select]if (!is_numeric ($someVar) || intval ($someVar) < 0){ throw new ErrorException ('Why do I see this message? Should I be logging your activity to report as a hacking incident?', 0, E_ERROR, __FILE__, __LINE__);}
However, I think it is important to still clean data, right when it comes from the user.
I think the underlying principle is that you can never be too paranoid.Validate data that your going to use...... if your expecting the user to enter a date within the next two weeks then you should be checking server side that the data supplied represents a date within the next two weeks....Clean data that your going to present back to the users.....character descriptions, avatar images, usernames etc...Track/Log as much as you canbasically assume that your users are out to cheat where ever possible....
avatar images
How do you guys remember to implement all these checks, etc?
Or, worse, upload a js file. IE will execute Javascript from files included as the target of an image tag.
Not to mention there's a slight flaw in the logic of that statement even if it was a good idea. You're checking the last 3 characters of the file extension, yet you have a 4 character extension listed as 'allowed.' It would never match. Here's a great read about upload security for those who are interested. It's quite involved.
But why not do it properly anyway?
But who said i was on about uploading? .. I dont get them to upload it to my server they use other sites like imageshark/tinypic ect