top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to prevent HTTP_REFERER from being overwritten in Wordpress?

0 votes
352 views

In the header.php file of my WordPress site I have the following code:

<?php
session_start();  
$_SESSION['refererurl'] = $_SERVER['HTTP_REFERER'];
?>

To test the above code, I placed the following code in the front-page.php file (and it works):

<?php
    echo $_SESSION['refererurl'];
?>

I want to track the referrer URL that led a visitor to my site from an external site for tracking purposes. The problem is that $_SERVER['HTTP_REFERER'] resets on page-load, so while the information is useful when a visitor first lands on my website, it's overwritten whenever the visitor navigates further into my site.

Is there any way to store the value of $_SERVER['HTTP_REFERER'] when a visitor first arrives at my site from an external site for as long as the visitor is on my site?

posted Jul 15, 2017 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Very simple - only set it if it isn't already set.

if(!isset($_SESSION['refererurl'])) {
$_SESSION['refererurl'] = $_SERVER['HTTP_REFERER'];
}

answer Jul 20, 2017 by Vipin
Similar Questions
0 votes

I am trying to export certain data from my PHP form to CSV. I can echo out to screen during testing and I can also export to CSV the static test data (stored in the $contents array) you see below. But I am stuck trying to export the certain fields that I only need to export.
This is my code

// How do I get this info into the CSV?
/*foreach ( $entries as $entry ) :  
    echo $entry['2'];
    echo $entry['3'];
    echo $entry['6'];
endforeach;*/

$csv_headers = [
    'Organisation Name',
    'Registered Charity Number',
    'Address',
    'Phone',
];

$contents = [
  [2014, 6, '1st half', 'roland@fsjinvestor.com', 0, 0],
  [2014, 6, '1st half', 'steve@neocodesoftware.com', 0, 0],
  [2014, 6, '1st half', 'susanne@casamanager.com', 0, 0],
  [2014, 6, '1st half', 'tim', 0, 0]
];

fputcsv($output_handle, $csv_headers);

foreach ( $contents as $content) :
    fputcsv($output_handle, $content);
endforeach;
0 votes

I need to force HTTPS for my e-commerce site, but when I try, it goes into an HTTPS -> HTTP -> HTTPS loop. I reviewed my .htaccess, by couple of experienced techs but they found no issue on that. I checked my wp_config.php, and nothing there. Where else should I be looking? How would I hunt this down?

0 votes

Do you know if there is a working module that can be used to post to WordPress from a Perl script? I've seen that all the modules that contain WordPress are very old.

I need to install that module under a Perl built with Perlbrew. I tried to install WordPress, WordPress::API, but they both depend on WordPress::XMLRPC which depends on SOAP::Lite which depends on XML::Parser which can't be installed because of the error "expat.h - no such file or directory".
I also tried to install XML::Parser::Expat but it gives the same error.

By curiosity I searched for a Python module, and I found python-wordpress-xmlrpc, I installed it very fast and easy, I found that it offers more features than the Perl module WordPress, I tested a sample script I found on the web, and it worked very well.

...