News: Welcome to the TinyPortal Support site.

Login  |  Register
HTML5 Icon HTML5 Icon
TP on Social Media
Welcome, Guest. Please login or register.
Did you miss your activation email?

July 23, 2019, 01:41:09 PM

Login with username, password and session length

Recent

Members
Stats
  • Total Posts: 188522
  • Total Topics: 20737
  • Online Today: 399
  • Online Ever: 629
  • (November 08, 2018, 01:36:54 PM)
Users Online
Users: 0
Guests: 36
Total: 36

Author Topic: View block by what country user is from?  (Read 7923 times)

0 Members and 1 Guest are viewing this topic.

mc

  • Guest
Re: View block by what country user is from?
« Reply #10 on: August 27, 2009, 08:32:50 AM »
JP is right.

Just re-read the original post again.
How about a simple re-direct page with the options for going to the ca or com website?
It would be a far simpler solution, unless you want to display country specific writing within the block..

JPDeni

  • Guest
Re: View block by what country user is from?
« Reply #11 on: August 27, 2009, 08:36:19 AM »
I'm finding that it's not that hard to find out the country, although I haven't had any Canadian members come by yet so I can't be sure that it picks up Canada.

I should have code for this tomorrow.

JPDeni

  • Guest
Re: View block by what country user is from?
« Reply #12 on: August 27, 2009, 09:05:18 AM »
If anybody wants to help, I have a page at http://www.morethanspike.com/index.php?page=35 to test it out. Since ApplianceJunk is particularly interested in Canadian visitors, it would be great if anybody from Canada would let me know if it works for you.

I noticed that some people get "XX" returned. So far it's just been folks in the US who have that, but it could be others as well.

Offline Freddy

  • Code
  • *
  • Posts: 1615
    • AiDreams
Re: View block by what country user is from?
« Reply #13 on: August 27, 2009, 09:16:04 AM »
Not from Canada of course, but just to let you know it worked...

"Your country is UK"

JPDeni

  • Guest
Re: View block by what country user is from?
« Reply #14 on: August 27, 2009, 09:23:25 AM »
Well, it looks like things are working, so I'll go ahead with the code.

Code: [Select]
$country = file_get_contents('http://api.hostip.info/country.php?ip='.$_SERVER['REMOTE_ADDR']);
if ($country == 'CA') {
  echo 'whatever you want to show to Canadian people';
}
elseif ($country == 'US' || $country == 'XX') {
  echo 'whatever you want to show to US people';
}
else {
  echo 'whatever you want to show to everyone else';
}

The variable $country will have an uppercase two-letter term that corresponds to the country. There is also 'XX' which so far appears to only show up for US folks, but it's possible that it's any place that the database can't determine.

Offline ZarPrime

  • Friends
  • *
  • Posts: 4653
Re: View block by what country user is from?
« Reply #15 on: August 27, 2009, 10:34:31 AM »
Works for me for US.

Offline IchBin™

  • Developer
  • *
  • Posts: 16228
    • My Website
Re: View block by what country user is from?
« Reply #16 on: August 27, 2009, 11:22:46 AM »
Using a Canadian proxy it indeed showed that I was from Canada. :) Good work Deni!

JPDeni

  • Guest
Re: View block by what country user is from?
« Reply #17 on: August 27, 2009, 11:24:22 AM »
Cool. Looks like it's working, then. It was just something I found on a Google search. :) It's a tool that can be used in a lot of different things.