Question

I have users coming from both organic and paid search.

organic users land on page.php, paid users land on page.php?source=paid.

A PHP variable on page.php would change according the source string, to help me identify where the user initially came from, for example, if he purchase something on my site right from the same page, I would have an indication.

The problem:

I have multiple pages in my website. once a paid user decides to navigate to another page such as page2.php, the indicating variable won't work, as he navigated to page2.php, and not to page2.php?source=paid.

So one possible messy solution, would be to drag the string all over the website, by placing on every link, an IF/ELSE that would insert at the end of all the href in the page, a ?source=paid string, in any case that the user initially landed with the ?source=paid string.

But, is there another option? I suppose there's a way to do this with cookies? but I have never dealt with cookies, and rather not to, unless it's easy.

Thanks

Pas de solution correcte

Autres conseils

This is exactly what sessions are for:

Sessions are a simple way to store data for individual users against a unique session ID. This can be used to persist state information between page requests. Session IDs are normally sent to the browser via session cookies and the ID is used to retrieve existing session data.

To solve this I would recommend you to use Sessions.

On the first page you need to set the session variable with something like this:

<?php>
session_start();
if isset($_GET['source']) {$_SESSION['source'] = $_GET['source'];}

and the rest of your first page goes here..

?>

On the other pages you can recall the sessionvariable like this:

<?php>
session_start();
if ($_SESSION['source'] == 'paid')
{ paid version}
else 
{unpaid version}

?>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top