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. 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. The isset () function is an inbuilt function in PHP which is used to determine if the variable is declared and its value is not equal to NULL. If the selected country is not found in one of the cases, the “default” case is assumed, and “Error!” is displayed. 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. In this case, each case is redirecting to the corresponding page to the selected country. arraykeyexists() is SLOW compared to isset(). Each case matches the variable passed the switch and performs all actions after that case up until a break statement. The switch method is basically a concise method of writing a bunch of “if” statements. ![]() 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. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |