Question

For a landing page campaign we're pulling in some variables from the url. I need a way to check and see if the 'utm_source=' is present in the url and if it is not redirect the user. We only want traffic from our banner ads, which all have Google Analtyics Links (incl. utm_source).

For example the url "http://www.example.com?utm_source=Google&utm_medium=AdWords&utm_term=Foo&utm_campaign=MyCampaign should work but the url "http://www.example.com" should get redirected to another page

<?php
     if (isset($_REQUEST['utm_source'])) {
    // param was set in the query string
    echo('present');
        if(empty($_REQUEST['utm_source'])) {
        // query string had param set to nothing ie ?param=&param2=something
        echo('missing');
        }
    }
 ?>

seems right but isn't working correctly. Is there a better way? thank you.

Was it helpful?

Solution

You seem to be missing the closing brace from the first if statement. That's the culprit.

You want:

if (isset($_REQUEST['utm_source']) && (!empty($_REQUEST['utm_source']))) {
    // param was set in the query string
    echo('present');
} else {
    // query string had param set to nothing ie ?param=&param2=something
    echo('missing');
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top