Go Back   vb.org Archive > vBulletin Modifications > Archive > vB.org Archives > vBulletin 2.x > vBulletin 2.x Full Releases

Reply
 
Thread Tools
Auto-Detect User Location At Registration Details »»
Auto-Detect User Location At Registration
Version: 1.00, by Raz Raz is offline
Developer Last Online: Nov 2023 Show Printable Version Email this Page

Version: 2.2.x Rating:
Released: 06-05-2003 Last Update: Never Installs: 9
 
No support by the author.

Simple hack making use of the Directi Ip-to-Country Database (included).

What it does
Auto-detects which country user is from and auto-fills the location field on the registration form using their IP Address.

Installing
Import the 'ip2country' table attached into your forums database. Either use phpMyAdmin or from ssh.
(Make sure your mysql max_packet size is large enough to handle the ~2 Mb file -- otherwise try downloading this split table here)

Open up register.php and look for:
PHP Code:
        while ($profilefield=$DB_site->fetch_array($profilefields)) {
                
$profilefieldname "field$profilefield[profilefieldid]"
Above that place the following:
PHP Code:
// CUSTOM ADD AUTO LOCATION
$ip_number sprintf("%u",ip2long($REMOTE_ADDR));
$ct_array $DB_site->query_first("SELECT COUNTRY_NAME FROM ip2country WHERE $ip_number >= IP_FROM AND $ip_number <= IP_TO LIMIT 1");
$bbuserinfo['field2'] = ucwords(strtolower($ct_array['COUNTRY_NAME']));
// END CUSTOM ADD AUTO LOCATION 
Once you've done that, you're all set.

Show Your Support

  • This modification may not be copied, reproduced or published elsewhere without author's permission.

Comments
  #32  
Old 06-09-2003, 08:39 AM
Raz's Avatar
Raz Raz is offline
 
Join Date: Oct 2001
Posts: 84
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I don't know of a freely available database that does this.

For larger ISPs it would probably be wrong, as it would just show the HQ of the ISP (who the IPs are registered to).
Reply With Quote
  #33  
Old 07-14-2003, 05:26 AM
Pikok Pikok is offline
 
Join Date: Jul 2002
Posts: 53
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I made a small change to the code Tim Wheatley posted for the "member.php" file as follows..

Add:
PHP Code:
// CUSTOM ADD AUTO LOCATION 
$ip_number sprintf("%u",ip2long($REMOTE_ADDR));
$ct_array $DB_site->query_first("SELECT COUNTRY_NAME FROM ip2country WHERE $ip_number >= IP_FROM AND $ip_number <= IP_TO LIMIT 1");
if (!
$bbuserinfo['field2']) {
  
$bbuserinfo['field2'] = ucwords(strtolower($ct_array['COUNTRY_NAME']));
}
// END CUSTOM ADD AUTO LOCATION 
Above:
PHP Code:
  while ($profilefield=$DB_site->fetch_array($profilefields)) {
    
$profilefieldname="field$profilefield[profilefieldid]"
With the code Tim had posted, the location would be automatically changed to just the country whenever a user modified their profile. With the change I made though, the location will only be automatically changed if the location field is empty (i.e. the user hasn't filled in a location manually).

In other words, if the user already has something in the location field it won't be changed. If the location field is empty, it will be automatically filled in with the country name.
Reply With Quote
  #34  
Old 07-14-2003, 11:44 PM
Pikok Pikok is offline
 
Join Date: Jul 2002
Posts: 53
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I also made the following change so no user can leave the location field empty in their profile..

In "root/member.php" find:
PHP Code:
  // check extra profile fields
  
$userfields="";
  
$profilefields=$DB_site->query("SELECT profilefieldid,required,title,size,maxlength
                                  FROM profilefield
                                  WHERE editable = 1"
); 
And Add Below It:
PHP Code:
// CUSTOM ADD AUTO LOCATION 
if (!$field2) {
  
$ip_number sprintf("%u",ip2long($REMOTE_ADDR));
  
$ct_array $DB_site->query_first("SELECT COUNTRY_NAME FROM ip2country WHERE $ip_number >= IP_FROM AND $ip_number <= IP_TO LIMIT 1");
  
$field2 ucwords(strtolower($ct_array['COUNTRY_NAME']));
}
// END CUSTOM ADD AUTO LOCATION 
In "root/register.php" find:
PHP Code:
  // check extra profile fields
  
$userfields="";
  
$userfieldsnames="(userid";
  
$profilefields=$DB_site->query("SELECT maxlength,profilefieldid,required,title
                                  FROM profilefield
                                  WHERE editable = 1
                                  ORDER BY displayorder"
); 
And Add Below It:
PHP Code:
// CUSTOM ADD AUTO LOCATION 
if (!$field2) {
  
$ip_number sprintf("%u",ip2long($REMOTE_ADDR));
  
$ct_array $DB_site->query_first("SELECT COUNTRY_NAME FROM ip2country WHERE $ip_number >= IP_FROM AND $ip_number <= IP_TO LIMIT 1");
  
$field2 ucwords(strtolower($ct_array['COUNTRY_NAME']));
}
// END CUSTOM ADD AUTO LOCATION 
With these additions, if a user leaves the location field empty (either when registering or updating their profile), the country will be automatically inserted into the database. Resulting in no empty locations.
Reply With Quote
  #35  
Old 07-17-2003, 12:33 PM
tinbin tinbin is offline
 
Join Date: Mar 2003
Location: lincs uk
Posts: 56
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

How could i combine this hack with the Flagshack?
So that it looks up what country the IP is in and then update the countryflag next to the username.

Would this be hard to do?
Reply With Quote
  #36  
Old 08-10-2003, 05:38 AM
PurpleCow PurpleCow is offline
 
Join Date: Mar 2003
Posts: 222
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Pikok - The changes you mentioned, will they be the same for ver 2.3.0 also ??

I am really interested in this hack, let me know how your changes and this hack works on 2.3.0 ??

Thank you very much

Cheers
Reply With Quote
  #37  
Old 02-09-2007, 06:21 AM
msibm msibm is offline
 
Join Date: Aug 2002
Posts: 15
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Are there new version for 3.6.4?
Thanks.
Reply With Quote
  #38  
Old 02-10-2007, 12:21 AM
steven s's Avatar
steven s steven s is offline
 
Join Date: Aug 2004
Location: Greenville, SC
Posts: 572
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I was searching for something else entirely and came across this.

Quote:
Originally Posted by tinbin View Post
How could i combine this hack with the Flagshack?
So that it looks up what country the IP is in and then update the countryflag next to the username.
Quote:
Originally Posted by msibm View Post
Are there new version for 3.6.4?
Thanks.
I was thinking about the same thing about both posts.
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:06 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.06821 seconds
  • Memory Usage 2,305KB
  • Queries Executed 24 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (8)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_post
  • (1)navbar
  • (6)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (8)post_thanks_box
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (8)post_thanks_postbit_info
  • (7)postbit
  • (8)postbit_onlinestatus
  • (8)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete