0

I have this error when trying t activate my plugin:

Notice: Undefined index: HTTP_REFERER in /home/gateway/domains/gateway.nl/public_html/wp-content/plugins/myplugin/includes/admin/admin.php on line 48

On this line is this block:

//change upload directory
public function user_upload_files_dir($upload) {
    //check if this a user-edit page
    $current_page = basename($_SERVER['HTTP_REFERER']);
    $current_page_tmp = explode("?", $current_page);
    $current_page = $current_page_tmp[0];
    if ($current_page != "user-edit.php")
        return $upload;

I have done some homework but I can't understand if either my code is wrong, or it is somehow my browser refusing to give the user agent?

Jimmy
  • 12,087
  • 28
  • 102
  • 192

1 Answers1

2

From PHP documentation:

'HTTP_REFERER' The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.

In your case it's clearly not being sent, so really all you can do is to check:

if(isset($_SERVER['HTTP_REFERER'])) {
  //do what you need to do    
   }
else
{
   //it was not sent, default action
}
Fabio Marzocca
  • 1,573
  • 16
  • 36