mrooks1984 Posted October 20, 2011 Share Posted October 20, 2011 hi i am getting this message on a isset and not sure how to fix it Notice: Undefined index: option in <?php $option = $_GET['option']; $path = 'option/'; $extension = '.php'; if ( preg_match("#^[a-z0-9_]+$#i",$option) ){ $filename = $path.$option.$extension; include($filename); } ?> hope someone can help, please. Quote Link to comment https://forums.phpfreaks.com/topic/249473-notice-undefined-index-option-in-on-a-isset/ Share on other sites More sharing options...
awjudd Posted October 20, 2011 Share Posted October 20, 2011 It is happening because the $_GET variable 'option' doesn't exist (i.e. it is not in your query string). You can resolve this by doing something like ... $option = ''; if ( isset ( $_GET [ 'option' ] ) ) { $option = $_GET['option']; } That said, this is a fairly big security risk leaving it open like this ... ~juddster Quote Link to comment https://forums.phpfreaks.com/topic/249473-notice-undefined-index-option-in-on-a-isset/#findComment-1280896 Share on other sites More sharing options...
mrooks1984 Posted October 21, 2011 Author Share Posted October 21, 2011 thanks for your help, so what would i need to add to the code to make it secure. Quote Link to comment https://forums.phpfreaks.com/topic/249473-notice-undefined-index-option-in-on-a-isset/#findComment-1281108 Share on other sites More sharing options...
ManiacDan Posted October 21, 2011 Share Posted October 21, 2011 I find it odd that your thread title includes the answer to your problem. You said you were getting that error on an isset...but isset was the solution to your error. Anyway, don't include files based on user input. Use a switch statement with hard-coded include values to make sure the user hasn't figured out some way of including custom code on your site. -Dan Quote Link to comment https://forums.phpfreaks.com/topic/249473-notice-undefined-index-option-in-on-a-isset/#findComment-1281132 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.