Recursive PHP Syntax Checker
2
The following script is a single interface for pre-validating any HTML form. It lets you validate your form data the way you want, while handling the rudimentary tasks itself.
1) Change just one variable to make it work with $_GET or $_POST or $_REQUEST.
2) Name which elements are 'required' all at once in a hidden HTML text input.
3) Easily provide field descriptions in hidden HTML text inputs that you can use to print error statements.
4) Call a single function to print out error statements that you can easily style with CSS.
5) It automatically checks if fields marked 'required' have been filled out.
Most of the pre-validation code is from PHP 5: Unleashed by Sams Publishing. I found it extremely useful for a recent project. Sharing it here, I removed some unnecessary functions, and tried to simplify some points.
All the comments are my own; hopefully I provided more than enough explanation.
1) Change just one variable to make it work with $_GET or $_POST or $_REQUEST.
2) Name which elements are 'required' all at once in a hidden HTML text input.
3) Easily provide field descriptions in hidden HTML text inputs that you can use to print error statements.
4) Call a single function to print out error statements that you can easily style with CSS.
5) It automatically checks if fields marked 'required' have been filled out.
Most of the pre-validation code is from PHP 5: Unleashed by Sams Publishing. I found it extremely useful for a recent project. Sharing it here, I removed some unnecessary functions, and tried to simplify some points.
All the comments are my own; hopefully I provided more than enough explanation.
12
Over the summer, I worked on a project in which I needed to parse logfiles which were in the following format:
IP|USE|TIME>IP2|USE2|TIME2>
and so on.
When I parsed them to display the log file in a user-friendly fashion, I used the following code:
IP|USE|TIME>IP2|USE2|TIME2>
and so on.
When I parsed them to display the log file in a user-friendly fashion, I used the following code:
8
This function simply splits a file based on the splitter supplied and returns an array with the values. It's pretty much like the file() function. This script could be helpful in section editings.
12
Here's a little snippet I got from SitePoint that I now use all the time. Add the code below to the start of each script.
Basically, what this does is checks to see if magic_quotes_gpc() is enabled on the server, and if it is, then it gets rid of all the slashes that magic_quotes_gpc() adds to input from $_GET, $_POST and $_COOKIES globals.
It's a good snippet to use, because it negates the bad programming practices that having magic_quotes_gpc() lets you get away with, and means that you don't really on PHP to validate your input; you get to do it all yourself ;-)
Basically, what this does is checks to see if magic_quotes_gpc() is enabled on the server, and if it is, then it gets rid of all the slashes that magic_quotes_gpc() adds to input from $_GET, $_POST and $_COOKIES globals.
It's a good snippet to use, because it negates the bad programming practices that having magic_quotes_gpc() lets you get away with, and means that you don't really on PHP to validate your input; you get to do it all yourself ;-)
-17
A little function that does some basic checking for data input by a user. Should get rid of code injection ;-)
10
This simple function will check if a url is valid (going by parse_url()) and if it's 'online' - by seeing if it returns a 302, 301, or 200 status code.
5
This small snippet will not allow _POST requests from a 'foreign' domain. It relies on the HTTP_REFERER variable.
7
This function will reverse the affects of register_globals
9
This is a simple PHP script that will show whether a certain port/socket of a certain computer is currently open/active.
-5
This multiple-use PHP script will randomly generate content based on a randomly generated number.









