douzhaxian1267 2015-06-29 23:46
浏览 27

使用PHP显示基于位置的内容

I am trying to show content based on user location. For example, show if outside of the country, Australia.

I have been using the documentation from this link: http://www.geoplugin.com/webservices/php

This is the code I have been using. It will always show the echo even when I change the location.

<?php
require_once('geoplugin.class.php');
$geoplugin = new geoPlugin();
// If we wanted to change the base currency, we would uncomment the following         line
// $geoplugin->currency = 'EUR';

$geoplugin->locate();

echo "Geolocation results for {$geoplugin->ip}: <br />
".

"Country Name: {$geoplugin->countryName} <br />
".
"Country Code: {$geoplugin->countryCode} <br />
";

if ( $geoplugin->countryName != "Australia" ) {
//our visitor is not using the same currency as the base currency
echo "Show International Popup";
}
?>

Cheers

  • 写回答

1条回答 默认 最新

  • dongzha5934 2015-06-30 00:39
    关注

    Personally, If I was you, I'd go via the countryCode instead of the countryName. It's more "containable" in a sense.

    if($geoplugin->countryCode !== "AU") {
        // load your selector
    }
    

    On another note, what does your countryName/countryCode show? Is anything present in either of the variables?

    Make sure you have error reporting on, encase your calls are failing:

    ini_set('display_errors', 1);
    display_errors(-1); // or use E_ALL
    
    评论

报告相同问题?

悬赏问题

  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥20 java在应用程序里获取不到扬声器设备