php - Wordpress Plugin Undefined index: HTTP_REFERER


I have this error when trying t activate my plugin:

Notice: Undefined index: HTTP_REFERER in /home/gateway/domains/ 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?




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    
   //it was not sent, default action

People are also looking for solutions to the problem: php - Is it possible to mock "require" or "require_once" statement with Kahlan?


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.