Jump to content

Recommended Posts

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.

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.