keep a variable for all pages in memory from the url

Question

I downloaded a referrer plugin and it works fine I create my custom link and everything is fine:

https://testsite.com/?r=ty5x

I have a conversion system that tells me how many users have come to my site via the custom link

if you want to see the variable associated with the custom link on the display, just do this:

<?php
if (isset($_GET['r'])) {
    echo $_GET['r'];
}
?>

where the problem lies, that if the user changes the page and returns to the home page, obviously the url changes, how can I keep the variable r = in memory for the entire browsing session of the user

update $_SESSION

if in functions.php I write the code:

if (!session_id()) {
    session_start();
    $_SESSION['referrer']=$_GET['r'];

}

in front-page.php, write echo:

<?php
$ref=$_SESSION['referrer'];
echo $ref;
?>

It’s perfect, but as soon as I change the page even if I activate the session_start, the variable is not seen

example second page:

session_start();

$test = $_SESSION['referrer'];

echo $test;

I also tried to enter the $ _SESSION following this example:

function test() {
    global $hello;
    $hello = 'hello world';
}
add_action( 'after_setup_theme', 'test' );

and echo:

global $hello;
echo $hello;

but no result

i just want a way that once i get the variable from url r =, i can store it while the user goes through all the pages of the site, how can i do this?

0
, , user14055335 5 months 0 Answers 50 views 0

Leave an answer