At the beginning of the guide, we said that data filtering is the cornerstone of WEB application security in any language and on any platform. This includes verifying the data input to the application and the data output from the application, and a good software design can help developers:
Ensure that data filtering cannot be bypassed,
Ensure that illegal information does not affect Legal information, and
identifying the source of the data.
There are various views on how to ensure that data filtering cannot be bypassed, and two of them are more general than others and provide a higher level of assurance.
Scheduling Method
This method is scheduled with a single php script (via URL). Any other operations are included using include or require when necessary. This approach generally requires that each URL be passed a separate GET variable for dispatch. This GET variable can be thought of as a more simplified design that replaces the script name. For example:
http://a.org/dispatch.php?task=PRint_formdispatch.php is the only root file (Document root). It allows developers to do two very important things:
Implement some global security processing at the beginning of dispatch.php, and ensure that these processing cannot be bypassed.
Easy to determine where necessary to perform data filtering, especially in some special-purpose control flow operations.
Look at the following example for further discussion of the dispatch.php script:
If this is the only publicly accessible PHP script, One thing you can be sure of is that the design of this program ensures that the initial global security processing cannot be bypassed. It also makes it easy for developers to see the control flow of specific tasks. For example, it is easy to know without browsing the entire code: when $form_valid is true, end.inc is the only one displayed to the user; since it is before process.inc is included and has just been initialized to false, it can be determined that The internal logic of process.inc will set it to true; otherwise the form will be displayed again (possibly with an associated error message).
Note
If you use a directory-directed file such as index.php (instead of dispatch.php), you can use the URL address like this: http://a.org/?task=print_form.
You can also use ApacheForceType redirection or mod_rewrite to adjust the URL address: http://a.org/app/print-form.
Include methods
Another way is to use a single module, which is responsible for all security processing. This module is included at the front (or very front) of all public PHP scripts. Refer to the following script security.inc
[/code]
The following code ensures that $_POST['num'] is an integer:
[code]