phpnew Posted February 13, 2018 Share Posted February 13, 2018 Hi,I have a script that grabs the page where a certain action happens. If the http_referer is empty, I get the notice in my log file: PHP Notice: Undefined index: HTTP_REFERER. The code is below: $urlpx=parse_url(strtok($_SERVER["HTTP_REFERER"],'?'), PHP_URL_PATH); if(empty($urlpx)) { $urlp="NOREF"; } else { $urlp=$urlpx; } The rest after the first line is what I added in my attempt to make referer stop being undefined, but I still get the notices. I realized that the IF statement works fine, but notice is still there as no referer still gets reported from the first line of the code.Is it possible to prevent logging it from within the script? Something that would be added to the first line of the code?Please note that I do want all logging to be ON as it is now.Thank you Quote Link to comment Share on other sites More sharing options...
Zane Posted February 13, 2018 Share Posted February 13, 2018 Simple! Check and make sure that the index isn't undefined first! Make sure that the variable is set. If a variable is not set, then it is not defined; it is undefined. PHP has a built-in function for this called: isset() Formed from the words "is" and "set". It's rather intuitive! $urlpx = ""; if( isset($_SERVER['HTTP_REFERRER']) ) { $urlpx=parse_url(strtok($_SERVER["HTTP_REFERER"],'?'), PHP_URL_PATH); } Quote Link to comment Share on other sites More sharing options...
phpnew Posted February 15, 2018 Author Share Posted February 15, 2018 Thanks very much. Unfortunately, while trying it, I got way too many empty referrers in transaction reports. For reference, for the whole month of January, the percentage of empties was 0.8%. For the part of yesterday and today, more than 50%. This watches outgoing clicks on my own website and therefore there should be a referring page in the very most cases. Quote Link to comment Share on other sites More sharing options...
requinix Posted February 15, 2018 Share Posted February 15, 2018 A referrer won't be sent if you do a header(Refresh:) redirect, which is wrong to do anyways, or when going from HTTPS to HTTP. Do either of those apply to you? How is this script of yours being invoked? Quote Link to comment Share on other sites More sharing options...
phpnew Posted February 15, 2018 Author Share Posted February 15, 2018 Thank you. The script is included into a redirect HTML file (for the purpose of click conversion tracking), which calls a PHP redirect which finally takes a visitor out to a website of our affiliate partner. The steps are: - a click onto a link to HTML which includes the upper code in getpageurl.php. - the HTML itself has this code (m is a varibale that determines which link is to be used from PHP redirect, v5 is a variable to get populated by the internal referring page): <?php include "getpageurl.php"; $m = isset($_GET['m']) ? $_GET['m'] : null; $targetUrl = htmlentities('redirect.php?m='.urlencode($m) . '&v5='.urlencode($urlp)); ?> and <meta http-equiv="refresh" content="0;url=<?=$targetUrl?>"> The original part of getpageurl script was this (there's more in that script, to manipulate referring page and to write it into a flat file): $urlp=parse_url(strtok($_SERVER["HTTP_REFERER"],'?'), PHP_URL_PATH); The sales reporting for the last month showed less than 1% of empty referrers. More clicks happen (many do not convert to sales), and all of the empty ones get recorded in PHP error log file I maintain. This was an attempt to stop logging this particular event. Everything is HTTPS on my site. the affiliate redirect links are HTTP, but all is working in regards of that. I see HTTPS can be used now as well, so thanks for mentioning it, I'll update the links. Thank you Quote Link to comment Share on other sites More sharing options...
requinix Posted February 15, 2018 Share Posted February 15, 2018 That's a Refresh redirect. Can't do that. There's basically no reason ever to do an immediate redirect. You're sending the browser an HTML page that then redirects them to another page that then redirects them to another page. Two pages that do nothing but redirect. Get rid of the first one and link to redirect.php directly. Or something like that. Quote Link to comment Share on other sites More sharing options...
phpnew Posted February 15, 2018 Author Share Posted February 15, 2018 Thanks again. This was in order to put the AdWords conversion tracking code and GA code. Linking to redirect.php is the best option, I know. In any case, referrers were coming through. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.