I am trying to display city in my webpage content if that city is in Texas using php and a geo paid service. Why isn't my if....else statement working?
Paid SSL Geolocation service through ipstack. Host GoDaddy using cpanel
<html>
<h1>
<?php
$ip = $_SERVER['REMOTE_ADDR'];
$api_key = "myipstackkeygoeshere";
$freegeoipjson = file_get_contents("http://api.ipstack.com/".$ip."?access_key=".$api_key."");
$jsondata = json_decode($freegeoipjson);
$cityfromip = $jsondata->city;
$region_namefromip = $jsondata->region_name;
if ($region_namefromip = "Texas") {
echo "". $cityfromip ."";
} else {
echo "Texas";
}
?>
Services</h1>
</body>
</html>
I want the City to be displayed before "Services" if the visitor's location is in Texas (Example: "Dallas Services"). If visitor's location is not in Texas, I want "Texas" to display (Example: "Texas Services").
Before adding the if...else statement and using just echo "". $cityfromip ."";
the page would display city (no matter what state). With the if...else statement, no city displays. Where is my code going wrong?