Notice: Undefined Index: Http_Referer

Notice: Undefined index: HTTP_REFERER

HTTP_REFERER is not guaranteed to be sent by the client:

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

if(isset($_SERVER['HTTP_REFERER'])) {
//do what you need to do here if it's set
}
else
{
//it was not sent, perform your default actions here
}

Wordpress Plugin Undefined index: HTTP_REFERER

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
}

$_SERVER['HTTP_REFERER'] missing

From the documentation:

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.

http://php.net/manual/en/reserved.variables.server.php

How to use HTTP_REFERER in PHP

https://stackoverflow.com/a/60288899/7044855

Referrer isn't always set. You can set HTTP headers manually if you're testing using curl/postman/etc, but not if you were testing by simply hitting your script in a browser.

set referrer in postman

Using this key/value combination you should see the following output

<?php

$referer = $_SERVER['HTTP_REFERER'];

echo $referer;
// https://google.com

Error in $_SERVER['HTTP_REFERER']

This is because HTTP_REFERER is not set
you can try

if(isset($_SERVER['HTTP_REFERER']))
echo $_SERVER['HTTP_REFERER'];
else
echo 'HTTP_REFERER in not set';


Related Topics



Leave a reply



Submit