html - Stop PHP from running if a GET variable doesn't exist -


On my page, the user has a data to show which data is displayed. I used it only by using a dropdown list and got the parameter. It currently looks like this:

Form:

  & lt; Form method = "get" action = "content.php" & gt; & Lt; Choose name = "tutorial block" & gt; & Lt; Option value = "tuts1" & gt; Block One - Getting Started & lt; / Options & gt; & Lt; Option value = "tuts2" & gt; Block two & lt; / Options & gt; & Lt; Option value = "tuts3" & gt; Block three & lt; / Options & gt; & Lt; / Select & gt; & Lt; Input type = "submit" & gt; & Lt; / Form & gt;  

Script to load the data based on the user-selected option:

  & lt ;? Php $ var_value = $ _GET ['tutorial block']; Include '/includes/'.$var_value.'php'; ? & Gt;  

This works fine, and the PHP includes the correct file based on the user's choice, the issue is, if the user has not opted for an option, then only PHP The file does not paste errors, because it is looking for a file that is not there. Is there a way to prevent PHP scripts from running if the GET parameter is not set?

What you are doing now is the reason for some serious weaknesses. You can never trust user input

You should run your $ _ GET ['Tutorial Block'] against the whitelist here is an example for you.

  $ whitelist = array ('page', 'blockpage', // etc); If (ift ($ _GET ['tutorial block']) & amp; empty ($ _GET ['tutorial block']) {// now make sure it's in the whitelist if (! In_array ($ _GET ['tutorialblock'] , $ Whitelist); (die ('bad page');} Other (include / '/includes/' .$_GET) 'tutorialball'ass.' .php ';}} and {// page of user page Did not select ... do something here ..}  

The above is just a pseudo-code (example), yet user input is required. / Em>


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -