unable to acess $_GET when dynamically loaded

I’m not sure what is the problem here.

I am using a plugin in wordpress that displays a popup for the users to sign up to the mailing list.

Read More

In this plugin, I want to be able to add a variable in a hidden field to post along so I can tell if the user has come from a specific affiliate campaign.

In the url I have

http://example.com/?urlref=affname

and in the modal window that pops up I have coded:

<?php if(isset($_GET['urlref'])) { ?>
     // do stuff here
<?php } else { ?>
    <p>No Aff Link</p>
<?php } ?>

and what i am getting returned is No Aff Link

I have tried using

$_REQUEST['urlref']

but that does not work either.

I have added the above code into the site page (not in the popup) and it works. So it’s something to do with it being dynamically loaded I think.

Any ideas?

Related posts

3 comments

  1. Converting my comment to the answer :

    Reason for $_GET['urlref'] not accessible in pop up might be an request which change the URL as well as $_GET. so you will able to access $_GET['urlref'] in Site Page but not in pop up.

    So you can change your if condition in popup like below :

    $url = $_SERVER['HTTP_REFERER'];
    if (strpos($url,'urlref') !== false) {
        echo 'urlref exists.';
    } else {
        echo 'No urlref.';
    }
    

    Let me know if you have any doubt.

  2. If you want to load your affiliate variable dynamically then you need to store this variable in session or cookie:

    You just need to set session in your site page:

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

    Now you can get this $_SESSION['urlref'] in you model page as well through session.

  3. Maybe the hidden field that you want to add is not in the <form> tag, so that it is not sent to the server. Need more details with your problems (what’s plugin, HTML code,…)

Comments are closed.