![]() ![]() It takes the performance advantage of isset() while maintaining the correct checking result (i.e. A combination of these two (see below code) would help. If using method 2, it’s a good idea to validate the selected country first, to make sure it won’t result in a redirect to a malicious page. arraykeyexists() is SLOW compared to isset(). The second method is much more concise, but less secure because a malicious user could monkey around with the form and submit whatever value he wants. The first method requires writing more code, but is more secure because it ensures the form only redirects to 6 pre-programmed cases, or else displays an error message and ends execution. ![]() The second method is just passing the selected value to the header function to redirect to the correct page. If the selected country is not found in one of the cases, the “default” case is assumed, and “Error!” is displayed. In this case, each case is redirecting to the corresponding page to the selected country. Each case matches the variable passed the switch and performs all actions after that case up until a break statement. ![]() If a list of values separated by a comma is contained on a single line. The switch method is basically a concise method of writing a bunch of “if” statements. There must not be more than one statement per line. These two approaches have their pro’s and con’s. comment out the method you don't want to demonstrateĬase "France" : $redir = "France.html" break Ĭase "Mexico" : $redir = "Mexico.html" break Ĭase "Russia" : $redir = "Russia.html" break Ĭase "Japan" : $redir = "Japan.html" break ĭefault : echo( "Error!") exit() break note that both methods can't be demonstrated at the same time Echo( "There was an error with your form: \n ") ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |