-1

I use Geo Plugin for get user state/ County and store it in cookie. So website's data will display data from that state/ County. But issue is what if User Change State/ County then site will reload and again that included config file will call and set cookie to current state/ County from that Geo Plugin.

Here is my cookie code

// get user location
require_once(LIBRARY_DIR.'/geoplugin.class.php');

$geoplugin = new geoPlugin();
$geoplugin->locate();
setcookie("county", $geoplugin->region);

Now user change county from dropdown list then again it set to current county. what I do for prevent again to select default/ Current county from Geo Plugin ?

Shivam Pandya
  • 1,061
  • 3
  • 29
  • 64

1 Answers1

-1

Only set the cookie if it is not already set.

if( !isset( $_COOKIE['country'] ) )
     setcookie( 'country' , $geoplugin->region );
hakeemon
  • 1
  • 1