How can PHP be used to determine the true referrer when a user clicks on a Google Adwords ad?

When a user clicks on a Google Adwords ad, the referrer information is often lost due to Google's secure search feature. However, you can use a combination of PHP and JavaScript to capture the true referrer by storing the click ID in a cookie and then retrieving it on the landing page.

<?php
// Set the cookie with the click ID
if(isset($_GET['gclid'])) {
    setcookie('adwords_click_id', $_GET['gclid'], time() + 3600, '/');
}

// Retrieve the click ID from the cookie
$adwords_click_id = isset($_COOKIE['adwords_click_id']) ? $_COOKIE['adwords_click_id'] : '';

// Use the click ID to determine the true referrer
if(!empty($adwords_click_id)) {
    // Perform actions based on the adwords click ID
}
?>