I am using a Geotargeting PHP script on my website to show my visitors different content based on their GEO Location.
I would like to change my HTML Links dynamically with PHP so that let’s say users from the UK get http://www.domain.com/UK while users from US would get http://www.domain.com/US and so on…
I tried the following :
<?php
...
if(Location == 'UK') { $VARIABLE = "UK"; }
elseif (Location == 'US') { $VARIABLE = "US"; }
echo "<a href=\"www.domain.com/$VARIABLE\">$VARIABLE</a>\n";
?>
but it didnt work.
How can i insert a PHP Variable in a HTML code block ?
Make sure that Location is filled with a default country code. Or even better, make sure that $VARIABLE is filled with default UK, for example.
Also, you might aswell do this:
But if it’s empty then you would still get an empty anchor.
That works only if Location is actually having the country code information. Are you sure that Location shouldn’t be $Location or something? Test that by doing
die('Locations is: ' . Location);somewhere in your code.