LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-07-2013, 04:06 PM   #1
Dafydd
Member
 
Registered: Oct 2008
Posts: 344

Rep: Reputation: 29
SMF forum software SQL problem


My knowledge of SQL is zilch. This is my first venture into this language. I am the web admin for Texas FlyFishers. The forum software is SMF http://www.simplemachines.org/community/index.php

The code snippet below is from the support website. Instructed to paste this at the start of 'Register.template.php'.
Code:
// Version: 1.1.10; Register
/////////////////////////////////////////////////////////
// mod - 12-21-2009 - prevent certain "problem" countries from 
// registering based on their IP address....

// try and get the real IP address...
if (getenv('HTTP_CLIENT_IP')) {
    $ip_address = getenv('HTTP_CLIENT_IP');
}elseif (getenv('HTTP_X_FORWARDED_FOR')) {
    $ip_address = getenv('HTTP_X_FORWARDED_FOR');
}elseif (getenv('HTTP_X_FORWARDED')) {
    $ip_address = getenv('HTTP_X_FORWARDED');
}elseif (getenv('HTTP_FORWARDED_FOR')) {
    $ip_address = getenv('HTTP_FORWARDED_FOR');
}elseif (getenv('HTTP_FORWARDED')) {
    $ip_address = getenv('HTTP_FORWARDED');
}else {
    $ip_address = $_SERVER['REMOTE_ADDR'];
}

// Query for getting visitor countrycode
$country_query  = "SELECT country_code2,country_name FROM iptocountry ".
     "WHERE IP_FROM<=inet_aton('$ip_address') AND IP_TO>=inet_aton('$ip_address') ";

// Execute above query
$country_exec = mysql_query($country_query);

// Fetch record set 
$ccode_array=mysql_fetch_array($country_exec);

// get the country code from the array
$country_code=$ccode_array['country_code2'];

// get the country name from the array
$country_name=$ccode_array['country_name'];

if($country_code==''){$country_code='XX';}
if($country_name==''){$country_name='UNKNOWN';}

//print "$country_code, $country_name";

// countries registration is ALLOWED from
$allow_list[] = 'us'; // USA numbah wun
$allow_list[] = 'US'; // USA numbah wun
$allow_list[] = 'ca'; // Canada, eh?
$allow_list[] = 'CA'; // Canada, eh?
//$allow_list[] = 'PR'; // Puerto Rico
//$allow_list[] = 'VI'; // Virgin Islands, nice beaches
$allow_list[] = 'gb'; // Great Britain/UK, cheerio, guv
$allow_list[] = 'GB'; // Great Britain/UK, cheerio, guv
$allow_list[] = 'uk'; // Great Britain/UK, cheerio, guv
$allow_list[] = 'UK'; // Great Britain/UK, cheerio, guv
//$allow_list[] = 'SE'; // Sweden - always allow blondes!
$allow_list[] = 'au'; // Autralia - throw another dingo on the barbie, mate!
$allow_list[] = 'AU'; // Autralia - throw another dingo on the barbie, mate!
//$allow_list[] = 'FR'; // France, ze land of luuuuuuuuuv
//$allow_list[] = 'ZA'; // South Africa, shucks, why not...
//$allow_list[] = 'VG'; // British Virgin Islands, blimey, eh wot?
//$allow_list[] = 'GL'; // Greenland, too cold for most spammers 
//$allow_list[] = 'AQ'; // Antarctica (see 'Greenland')
//$allow_list[] = 'IO'; // British Indian Ocean territory
//$allow_list[] = 'AS'; // American Samoa (they're Yanks, sort of)

if(!in_array($country_code, $allow_list)){

print <<<EOM
    <html><head></head>
    <body bgcolor="#dcdcdc">
    Registration for your country is disabled. Sorry.
    </body></html>
EOM;

exit;
}
/////////////////////////////////////////////////////////

The SQL is as follows: My 'Hostmonster' 'myphpadmin' tells me I got a successful install.
Code:
DROP TABLE IF EXISTS iptocountry;

CREATE TABLE iptocountry (
  ip int(11) unsigned NOT NULL default '0',
  country char(2) NOT NULL default '',
  KEY ip (ip)
);

DROP TABLE IF EXISTS iptocountryCountries;
      
CREATE TABLE iptocountryCountries (
  code varchar(4) NOT NULL default '',
  iso_code_2 varchar(2) NOT NULL default '',
  iso_code_3 varchar(3) default '',
  iso_country varchar(255) NOT NULL default '',
  country varchar(255) NOT NULL default '',
  lat float NOT NULL default '0',
  lon float NOT NULL default '0',  
  PRIMARY KEY  (code),
  KEY code (code)
);
INSERT INTO iptocountry (ip, country) VALUES(0, 'us');
INSERT INTO iptocountry (ip, country) VALUES(687865856, 'za');
INSERT INTO iptocountry (ip, country) VALUES(689963008, 'eg');

And ends 59348 lines later with this:
INSERT INTO iptocountryCountries (code, iso_code_2, iso_code_3, iso_country, country, lat, lon) VALUES('eu', '', '', '', 'Europe', 0, 0);
INSERT INTO iptocountryCountries (code, iso_code_2, iso_code_3, iso_country, country, lat, lon) VALUES('01', '', '', '', 'Private', 0, 0);
INSERT INTO iptocountryCountries (code, iso_code_2, iso_code_3, iso_country, country, lat, lon) VALUES('ps', 'PS', 'PSE', 'Palestinian Territory, Occupied', 'Palestinian Territory, Occupied', 31.89, 34.9);
INSERT INTO iptocountryCountries (code, iso_code_2, iso_code_3, iso_country, country, lat, lon) VALUES('me', 'ME', 'MNE', 'Montenegro', 'Montenegro', 42.74, 19.31);
When I try to register, I get the 'Registration for your country is disabled. Sorry.' message on my browser screen.
I am at a lose where/what to trouble shoot. Can some one get me on the path to recovery??

Thanks for any insight you have to offer.
Dave
 
Old 03-13-2013, 05:47 PM   #2
Dafydd
Member
 
Registered: Oct 2008
Posts: 344

Original Poster
Rep: Reputation: 29
Not really solved, I'm going to approach from a different direction.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
AWK: Usr seeks rec’d “forum” for GAWK -eq SQL manip. ajaxStardust Programming 3 12-02-2012 12:42 AM
Smf linuxtesting2 Solaris / OpenSolaris 1 08-23-2006 09:39 AM
sql error cant register on the gentoo forum ramraid Linux - Newbie 2 11-02-2005 02:40 AM
Forum by PHP (without SQL) swmok Linux - Software 3 03-16-2005 09:07 PM
Problem with starting CUPS in Slackware 10 (copy from the Software forum) SlawioG Slackware 2 12-13-2004 05:38 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration