Skip to main content
update
Source Link
wlh
  • 121
  • 1
  • 10

There were three problems I discovered with my code above.

First, $_SERVER["HTTP_REFERRER"]; is an undefined index, moreover it is mispelled - HTTP_REFERER would be correct if it could be accessed this way in WP. I found get_http_origin() instead.

$data['UrlReferer'] = get_http_origin();

Second, I also mispelled the field I was saving this variable to - UrlReferrer (bad), UrlReferer (correct), something only I could have detected by testing on my end. But I wouldn't have caught this if I didn't catch the first.

Third, I dropped $data['ClientBrowser'] = $_SERVER["HTTP_USER_AGENT"]; since I can get that client side.

UPDATE

I can also get the URL referrer from the client side as well, by passing window.location.href to the api.

There were three problems I discovered with my code above.

First, $_SERVER["HTTP_REFERRER"]; is an undefined index, moreover it is mispelled - HTTP_REFERER would be correct if it could be accessed this way in WP. I found get_http_origin() instead.

$data['UrlReferer'] = get_http_origin();

Second, I also mispelled the field I was saving this variable to - UrlReferrer (bad), UrlReferer (correct), something only I could have detected by testing on my end. But I wouldn't have caught this if I didn't catch the first.

Third, I dropped $data['ClientBrowser'] = $_SERVER["HTTP_USER_AGENT"]; since I can get that client side.

There were three problems I discovered with my code above.

First, $_SERVER["HTTP_REFERRER"]; is an undefined index, moreover it is mispelled - HTTP_REFERER would be correct if it could be accessed this way in WP. I found get_http_origin() instead.

$data['UrlReferer'] = get_http_origin();

Second, I also mispelled the field I was saving this variable to - UrlReferrer (bad), UrlReferer (correct), something only I could have detected by testing on my end. But I wouldn't have caught this if I didn't catch the first.

Third, I dropped $data['ClientBrowser'] = $_SERVER["HTTP_USER_AGENT"]; since I can get that client side.

UPDATE

I can also get the URL referrer from the client side as well, by passing window.location.href to the api.

Source Link
wlh
  • 121
  • 1
  • 10

There were three problems I discovered with my code above.

First, $_SERVER["HTTP_REFERRER"]; is an undefined index, moreover it is mispelled - HTTP_REFERER would be correct if it could be accessed this way in WP. I found get_http_origin() instead.

$data['UrlReferer'] = get_http_origin();

Second, I also mispelled the field I was saving this variable to - UrlReferrer (bad), UrlReferer (correct), something only I could have detected by testing on my end. But I wouldn't have caught this if I didn't catch the first.

Third, I dropped $data['ClientBrowser'] = $_SERVER["HTTP_USER_AGENT"]; since I can get that client side.