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.
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
Flex/Grid Properties Are Deleted in Gmail Email
How to Merge Subarray Values and Remove Duplicates
Phpstorm 2020.2 - PHP Built-In Functions Are Not Recognized
Warning: File_Get_Contents: Failed to Open Stream: Redirection Limit Reached, Aborting
Getting All $_Post from Multiple Select Value
Is There a Difference Between Instantiation with Parentheses or Without
Codeigniter "Flashdata" Doesn't Work
Phpexcel Allowed Memory Size of 134217728 Bytes Exhausted
Convert a Big Integer to a Full String in PHP
No Database Selected - PHP & MySQL
Can't Connect to Postgresql with PHP Pg_Connect()
Confirmation That PHP Static Variables Do Not Persist Across Requests
In Htaccess, I'D Like to Replace Underscores with Hyphens and Then Redirect the User the New Url
How to Recursively Obtain the "Parent Id" of Rows in This MySQL Table