Back to Geo Location Support

j_depad1326212
j_depad1326212

Hi!

I am trying to redirect visitors to my page using your plugin.

I added this code in my default.htm file before the <!DOCTYPE html>

use Raccoon\GeoLocation\Facades\Geo;

function onStart() {
$geoLocation = Geo::getLocation($ipAddress);    
  if ($geoLocation->countryCode === 'UY') {
    header('Location: https://www.elpais.com.uy/');
    die();
 } 

}

but I get this error: "Undefined variable: ipAddress"

I am new at this, sorry if I am missing something obvious.

j_depad1326212
j_depad1326212

I solved the problem.

The code will be this:

use Raccoon\GeoLocation\Facades\Geo;

function onStart() {
$ipAddress = $_SERVER['REMOTE_ADDR']?:($_SERVER['HTTP_X_FORWARDED_FOR']?:$_SERVER['HTTP_CLIENT_IP']);   
$geoLocation = Geo::getLocation($ipAddress);    
  if ($geoLocation->countryCode === 'UY') {
    header("Location: https://www.elpais.com.uy/");
    die();
 } 

}

1-2 of 2