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=¶m2=something
echo('missing');
}
}
?>
seems right but isn't working correctly. Is there a better way? thank you.
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=¶m2=something
echo('missing');
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.