打印

[php] 禁止国外IP访问 代码 看一下吧 谢谢~

<?
function chinaIP($ip) {
$str="973996032       974782463
975044608       977272831
977403904       977534975
977567744       977600511
978452480       978583551
978796544       978812927
979599360       979763199
980680704       980942847
981467136       981991423
982515712       982581247
983171072       983302143
985661440       987758591
988807168       989855743
991952896       995360767
996868096       997195775
999751680       999784447
1000013824       1000079359
1001127936       1001390079
1002373120       1002405887
1002434560       1008730111
1010237440       1010302975
1010761728       1010827263
1017118720       1019215871
1019346944       1019478015
1019740160       1021313023
1021837312       1021968383
1022033920       1022099455
1022722048       1022754815
1022820352       1022885887
1023148032       1023213567
1023246336       1023279103
1023344640       1023410175
1023692800       1023696895
1023717376       1023721471
1023975424       1023979519
1024335112       1024335119
1024335184       1024335199
1025245184       1025277951
1025295104       1025295615
1025343488       1025376255
1026392064       1026408447
1026523136       1026539519
1026555904       1027080191
1029160960       1029177343
1031798784       1033982787
1033982789       1034001207
1034001216       1035993087
1037591500       1037591503
1038614528       1039007743
1039138816       1039400959
1050616656       1050616671
1066828152       1066828159
1067617792       1067618047
1067934912       1067934927
1073120286       1073120295
1073120632       1073120639
1073126328       1073126337
1075995568       1075995583
1076029952       1076030207
1076034048       1076034063
1077843720       1077843727
1077858016       1077858047
1077870336       1077870591
1078433632       1078433663
1078438912       1078439167
1082091264       1082091271
1088453857       1088453870
1091798640       1091798647
1091798784       1091799039
1091803136       1091803391
1091812352       1091812607
1097742682       1097742691
1109776576       1109776607
1113640397       1113640416
1114584520       1114584529
1115074680       1115074687
1117815296       1117815551
1117823488       1117823743
1122267392       1122267399
1137378320       1137378335
1137536000       1137536007
1138015120       1138015127
1139018992       1139018999
1139019848       1139019855
1139042032       1139042039
1163870576       1163870583
1163878400       1163878407
1211602240       1211602247
1211609000       1211609007
1224315584       1224315647
1247152664       1247152679
1247152768       1247152783
1247152880       1247152887
1247153120       1247153127
1247154008       1247154015
1247154432       1247154439
1247155520       1247155527
1247155536       1247155543
1247155552       1247155583
1247156592       1247156599
1247157032       1247157039
1247157264       1247157271
1247157736       1247157743
1247157992       1247157999
1247159168       1247159175
1247159352       1247159359
1247159680       1247159687
1247161104       1247161119
1249846880       1249846911
1266550864       1266550871
1266552968       1266552975
1266553048       1266553055
1266554432       1266554439
1266555432       1266555439
1266555760       1266555767
1266556976       1266556983
1266557032       1266557039
1266557096       1266557103
1266557328       1266557335
1266557344       1266557359
1266560208       1266560215
1266560664       1266560671
1266560720       1266560735
1266562416       1266562431
1266563280       1266563295
1266563360       1266563375
1266568800       1266568831
1266597200       1266597207
1266598528       1266598535
1266598544       1266598551
1266598664       1266598671
1266598800       1266598807
1266601384       1266601391
1266609408       1266609415
1266609520       1266609527
1279962912       1279962927
1279962944       1279962975
1310247248       1310247263
1310247464       1310247471
1310247720       1310247727
1310248488       1310248495
1317114624       1317114879
1317134656       1317134719
1317137280       1317137343
1351800352       1351800359
1441384608       1441384639
1539631104       1539632127
1895825408       1896480767
1896595456       1896603647
1896611840       1897070591
1897398272       1897660415
1897857024       1897922559
1898708992       1899233279
1899274240       1899282431
1899364352       1899724799
1914437632       1914503167
1916141568       1916272639
1916534784       1917124607
1917845504       1919680511
1919811584       1919815679
1919827968       1919844351
1919877120       1919885311
1919918080       1919926271
1919942656       1920466943
1921253376       1921318911
1921449984       1921515519
1921646592       1921777663
1921875968       1921892351
1925447680       1925578751
1926234112       1929379839
1930952704       1931345919
1931476992       1931739135
1932263424       1933574143
1934884864       1934901247
1934934016       1934942207
1934999552       1935015935
1935933440       1936457727
1937244160       1937506303
1937510400       1937514495
1939079168       1939865599
1940389888       1940914175
1941176320       1941438463
1941962752       1945108479
1946222592       1946943487
1947009024       1947074559
1947205632       1948254207
1949564928       1949958143
1949990912       1949995007
1950011392       1950015487
1950089216       1950351359
1950482432       1950515199
1950679040       1950777343
1951137792       1951399935
1952026624       1952030719
1952075776       1952079871
1952102400       1952104447
1952382976       1952448511
1953497088       1953890303
1954545664       1958805503
1958809600       1958821887
1958871040       1959067647
1959133184       1959239679
1959526400       1959657471
1959723008       1960050687
1960080128       1960080383
1960091648       1960095743
1960132608       1960181759
1960189952       1960202239
1960213504       1960213759
1960214528       1960574975
1960837120       1961885695
1962016768       1962541055
1962672128       1962803199
1962835968       1962868735
1962901504       1962934271
1963458560       1963982847
1964310528       1965948927
1966080000       1966342143
1966419968       1966424063
1966452736       1966456831
1966669824       1966768127
1966800896       1967783935
1967800320       1967804415
1967816704       1969225727
1969487872       1969618943
1969688576       1969692671
1969717248       1969721343
1969881088       1970012159
1970274304       1970798591
1970814976       1970915327
1970962432       1970995199
1971060736       1975517183
1981284352       1981808639
1983905792       1984102399
1984131072       1984135167
1984430080       1985085439
1985216512       1985347583
1985486848       1985609727
1985736704       1985740799
1986400256       1986404351
1986523136       1986525183
1987051520       1988034559
1988362240       1988624383
1989148672       1989410815
1991376896       1991442431
1991507968       1993342975
1993605120       1993736191
1994391552       1994850303
1995374592       1995440127
1995571200       1995636735
1995702272       1996627967
1996652544       1997176831
1997506560       1997508607
1997537280       1997602815
1997717504       1997723647
1997725696       1998061567
1998274560       1998290943
1998299136       1998454783
1998467072       1998471167
1998569472       1998577663
1998585856       1999130623
1999142912       1999249407
1999276032       1999278079
1999298560       1999306751
1999372288       1999503359
1999634432       2000158719
2000224256       2000355327
2000388096       2000617471
2000625664       2000633855
2001457152       2001461247
2001600512       2001862655
2001993728       2002518015
2002780160       2003304447
2003566592       2003697663
2003828736       2006188031
2006228992       2006233087
2007072768       2007498751
2008023040       2009071615
2011693056       2011824127
2011922432       2011938815
2012741632       2013003775
2013069312       2014314495
2014838784       2015100927
2015232000       2016542719
2016673792       2016935935
2017460224       2017984511
2017992704       2018000895
2018017280       2018050047
2018246656       2019033087
2019164160       2019360767
2019426304       2019557375
2021654528       2022178815
2022211584       2022227967
2022244352       2022277119
2025848832       2030043135
2030047232       2030051327
2030305280       2030436351
2030567424       2032926719
2033057792       2033319935
2033385472       2033451007
2033491968       2033500159
2033504256       2033516543
2033647616       2033663999
2033713152       2033876991
2033881088       2033885183
2033909760       2034213775
2034213784       2034213787
2034213792       2034237439
2034499584       2034761727
2035023872       2035154943
2035253248       2035269631
2035875840       2035941375
2036629504       2036662271
2036715520       2036719615
2042626048       2043150335
2043215872       2043281407
2043412480       2043674623
2044723200       2045771775
2046296064       2046558207
2046754816       2046820351
2046836736       2046885887
2047082496       2047868927
2049966080       2050047999
2050162688       2050228223
2051014656       2053242879
2053505024       2053509119
2053521408       2053529599
2054160384       2054422527
2054619136       2054684671
2055733248       2056257535
2056290304       2056323071
2056830976       2056847359
2057043968       2057306111
2059403264       2059665407
2059796480       2059862015
2059943936       2059960319
2060189696       2060451839
2061500416       2063073279
2063085568       2063089663
2063630336       2063646719
2063859712       2064646143
2066841600       2066874367
2067005440       2070052863
2070118400       2070159359
2070210560       2070210815
2070216704       2070282239
2070347776       2070380543
2070708224       2070712319
2070728704       2070732799
2070937600       2072510463
2072530944       2072535039
2072576000       2072772607
2073034752       2075131903
2075152384       2075156479
2075197440       2076180479
2076442624       2076573695
2076672000       2076704767
2077097984       2077229055
2078801920       2079064063
2079457280       2079490047
2079588352       2079850495
2079916032       2079981567
2080178176       2080243711
2080784384       2080800767
2081292288       2081554431
2081685504       2081947647
2082258944       2082308095
2082406400       2082471935
2083024896       2083045375
2083127296       2083192831
2083454976       2083471359
2084569088       2084732927
2084765696       2085617663
2086141952       2086666239
2087454720       2087456767
2087462912       2087464959
2087714816       2088239103
2088632320       2089287679
2090041344       2090074111
2090598400       2090663935
2090860544       2091384831
2091646976       2091909119
2092957696       2093088767
2093219840       2093285375
2093481984       2094006271
2094792704       2096152575
2096234496       2096300031
2096349184       2096365567
2096627712       2096660479
2096693248       2096889855
2097020928       2097037311
2099232768       2100297727
2100985856       2101018623
2101182464       2101231615
2101346304       2103640063
2103967744       2105540607
2108227584       2108293119
2108358656       2108424191
2110783488       2110799871
2110914560       2111045631
2111111168       2111143935
2111201280       2111209471
2111242240       2111258623
2111307776       2111832063
2113830912       2113863679
2260992000       2261057535
2482233344       2482241535
2682388480       2682454015
2714697728       2714763263
2724790272       2724855807
2792292352       2792357887
2810904576       2810970111
2829058048       2829123583
2849177856       2849178111
3226696192       3226696447
3229391360       3229391615
3230211840       3230212095
3233589760       3233590015
3240207872       3240208383
3252449280       3252449535
3262473517       3262473517
3262473527       3262473527
3262474027       3262474027
3262474042       3262474042
3262474062       3262474063
3262474104       3262474104
3262474107       3262474107
3262474134       3262474134
3262474138       3262474139
3262474165       3262474165
3262474173       3262474173
3262474179       3262474179
3262474190       3262474190
3262474199       3262474199
3262474202       3262474203
3262474214       3262474214
3262478181       3262478181
3278939924       3278939927
3278939960       3278939963
3278939988       3278939991
3278940060       3278940067
3278942484       3278942487
3278942496       3278942499
3278942588       3278942591
3278946060       3278946060
3323004672       3323004927
3338916352       3338916479
3389025792       3389026047
3389165632       3389165695
3389292544       3389300735
3389324288       3389325311
3389554688       3389562879
3389669376       3389673471
3389937664       3389937919
3389975296       3389976319
3390339072       3390339327
3390502912       3390504959
3391488000       3391492095
3391504384       3391524863
3391525376       3391525887
3391526144       3391526655
3391526912       3391528191
3391528448       3391529471
3391529984       3391533567
3391535104       3391553535
3391720960       3391721215
3391723520       3391725567
3391746048       3391750143
3391852544       3391856639
3392020480       3392028671
3392069632       3392073727
3392958464       3392962559
3393189888       3393190911
3393520640       3393521663
3393523712       3393527807
3393585152       3393593343
3393626368       3393630207
3393849344       3393851391
3393966080       3393970175
3394087472       3394087487
3394621440       3394625535
3394835712       3394835967
3394895872       3394896895
3394953216       3394957311
3394960384       3394962431
3394994176       3394995199
3395006464       3395010559
3395018752       3395027967
3395091456       3395093503
3395156992       3395158015
3395223552       3395231743
3395288064       3396868319
3396868352       3396995071
3397001216       3397003263
3397009408       3397017599
3397021696       3397023743
3397025792       3397026047
3397083136       3397087231
3397130240       3397131263
3397234688       3397238783
3397320704       3397322751
3397323776       3397328895
3397330944       3397337087
3397349376       3397363711
3397369856       3397386239
3397517312       3397525503
3397574656       3397582847
3397586944       3397588991
3397595136       3397599231
3397636096       3397640191
3397922816       3397926911
3397963776       3397971967
3398279168       3398287359
3398307840       3398311935
3398373376       3398377471
3398721536       3398729727
3398803456       3398811647
3398819840       3398828031
3398832128       3398836223
3399004160       3399008255
3399036928       3399041023
3399074496       3399074527
3399393280       3399401471
3399528448       3399532543
3399745536       3399749631
3399856128       3399860223
3399864320       3399868415
3400048640       3400056831
3400171520       3400179711
3400194048       3400196095
3400337408       3400339455
3400392704       3400400895
3400790016       3400794111
3400826880       3400835071
3400888320       3400892415
3401404416       3401408511
3401580544       3401642495
3401642752       3402629119
3406967296       3406967551
3410952192       3410956287
3411054592       3411058687
3411087360       3411091455
3411228672       3411230719
3411410944       3411435519
3411550208       3411558399
3411591168       3411599359
3411607552       3411608575
3411673088       3411674111
3411705856       3411730431
3411746816       3411755007
3411763200       3411767295
3411769344       3411771391
3411804160       3411805183
3411845120       3411853311
3411869696       3411943423
3412000768       3412002815
3412025344       3412033535
3412246952       3412246959
3412247024       3412247031
3412247056       3412247071
3412247344       3412247359
3412248832       3412249087
3412249888       3412249903
3412250024       3412250031
3412250368       3412250375
3412250448       3412250479
3412251008       3412251071
3412251136       3412251151
3412251232       3412251239
3412251928       3412251935
3412252080       3412252087
3412267008       3412271103
3412283392       3412287487
3412336640       3412340735
3412348928       3412361215
3412377600       3412381695
3413024768       3413032959
3413557248       3413565439
3413571584       3413572607
3413579776       3413582847
3414171648       3414179839
3414188032       3414196223
3414302720       3414310911
3414433792       3414441983
3414618112       3414620159
3414646784       3414654975
3414663168       3414667263
3415084032       3415084543
3415137024       3415137279
3415474176       3415490559
3415752704       3415760895
3416047616       3416063999
3416133632       3416135679
3416375296       3416383487
3416694784       3416702975
3417038848       3417042943
3417179904       3417180159
3417202688       3417210879
3417276416       3417284607
3417292800       3417309183
3417352192       3417354239
3417853952       3417858047
3418071040       3418079231
3418251264       3418255359
3418296320       3418300415
3418308608       3418324991
3418329088       3418333183
3418357760       3418365951
3418524575       3418524606
3418619904       3418621951
3419357184       3419411455
3419414528       3419422719
3419529216       3419537407
3419668480       3419672575
3419688960       3419693055
3419902464       3419902719
3420335272       3420335279
3420366432       3420366439
3420366528       3420366591
3420366648       3420366655
3420366720       3420366735
3420368584       3420368591
3420369140       3420369223
3420369256       3420369263
3420369344       3420369407
3420370528       3420370543
3420370576       3420370591
3420371888       3420371895
3460906080       3460906111
3460913952       3460914015
3460940608       3460940639
3460944480       3460944511
3460948800       3460948863
3460953632       3460953647
3467146656       3467146671
3468085200       3468085207
3468085376       3468085439
3468090736       3468090751
3468090816       3468090879
3470656184       3470656191
3480593664       3480593919
3482755102       3482755111
3482757576       3482757585
3486633600       3486633727
3492517696       3492517711
3492519240       3492519247
3496282752       3496282759
3496284544       3496284551
3496287424       3496287431
3496291304       3496291311
3496292096       3496292103
3496292816       3496292823
3496293856       3496293863
3496294304       3496294319
3509352320       3509352383
3509777160       3509777167
3509831312       3509831319
3509832080       3509832087
3509837096       3509837103
3512561152       3512561279
3512561792       3512561919
3512562304       3512562367
3512578560       3512578720
3512580288       3512580351
3512581376       3512582143
3512582720       3512582783
3512593512       3512593519
3512594048       3512594175
3512594560       3512594687
3518896232       3518896239
3518921448       3518921455
3523346432       3523354623
3523543040       3523551231
3523579904       3523583999
3524001792       3524132863
3524149248       3524157439
3524161536       3524247551
3524296704       3524313087
3524591616       3524722687
3524730880       3524739071
3524853760       3525300739
3525300744       3526361087
3526557696       3526754303
3526934528       3526942719
3527933952       3528392703
3528409088       3528425471
3528450048       3528458239
3528589312       3528720383
3528949760       3528966143
3535388672       3535405055
3535822848       3535831039
3544186880       3544711167
3545235456       3546808319
3548905472       3551002623
3560944924       3560944927
3560944936       3560944943
3560944972       3560944975
3560945036       3560945039
3560945076       3560945083
3560945096       3560945099
3560945120       3560945123
3560945412       3560945412
3560945417       3560945418
3560945423       3560945423
3560945427       3560945427
3560945431       3560945431
3560945436       3560945436
3560945466       3560945466
3560945470       3560945470
3560945472       3560945472
3560945476       3560945476
3560945620       3560945627
3560945636       3560945639
3630065920       3630066175
3630068864       3630068991
3632826496       3632826511
3632833232       3632833247
3632838584       3632838591
3632847280       3632847295
3633035088       3633035095
3634270017       3634270080
3634270977       3634271231
3635658752       3635660799
3636668672       3636668927
3636909856       3636909887
3638208528       3638208543
3638220512       3638220519
3641206016       3641206271
3656650624       3656650687
3657433088       3659530239
3661103104       3663986687
3664248832       3664642047
3669606400       3669614591
3670016000       3671064575
3673161728       3673686015
3673751552       3673817087
3678928896       3678994431
3679584256       3679649791
3682598912       3684696063
3688366080       3689938943
3690070016       3690463231
3697655808       3697672191
3698327552       3698589695
3700981760       3701014527
3701080064       3701211135
3701473280       3704619007
3706126336       3706142719
3706159104       3706191871
3706208256       3706224639
3706322944       3706388479
3706847232       3706978303
3707240448       3707568127
3707764736       3708600319
3708616704       3708813311
3715760128       3715891199
3716218880       3716415487
3716538368       3716546559
3716677632       3716808703
3719036928       3719823359
3720347648       3720859647
3720863744       3723493375
3725590528       3730833407
3732733952       3732799487
3732832256       3732865023
3732930560       3733979135
3735027712       3735289855
3735552000       3739222015
125.141.139.0       125.141.139.255
3740270592       3740925951";

       $arr=explode(".",$ip);
       $ipn=$arr[0]*256*256*256+$arr[1]*256*256+$arr[2]*256+$arr[3];

       $arr=explode("\n",$str);
       foreach($arr as $str2) {
              $arr2=explode("\t",$str2);
              $n1=intval($arr2[0]);
              $n2=intval($arr2[1]);
              if ($n1<1000) {              
                     $arr3=explode(".",$arr2[0]); $n1=$arr3[0]*256*256*256+$arr3[1]*256*256+$arr3[2]*256+$arr3[3];
                     $arr3=explode(".",$arr2[1]); $n2=$arr3[0]*256*256*256+$arr3[1]*256*256+$arr3[2]*256+$arr3[3];
                     
              }
              if ($ipn >= $n1 && $ipn <= $n2){
                     
                     return true;
              }
       }
       return false;
}

if (chinaIP(getenv("REMOTE_ADDR"))) {
       exit;
}

?>


这是禁止中国IP访问的 代码,
想把某个国家的 IP 禁止访问的话  怎么改啊?
假如美国国家的所有IP 禁止访问的话 怎么做呢?
希望能详细的告诉一下 谢谢
你需要知道美国的IP段!
说到底还是你需要收集美国所有的IP数据,然后用函数 ip2long转成这个格式再判断!
PNG2HTML、PHP定制 QQ:31301678
BlueIdea山东群:4398616
可以用纯真的IP库进行查询的,网上有现成的分析读取纯真IP库的代码
<?php
/**
* @author 马秉尧
*/

class IpLocation {

/**
* QQWry.Dat文件指针
* @var resource
*/

var $fp;

/**
* 第一条IP记录的偏移地址
*
* @var int
*/

var $firstip;

/**
* 最后一条IP记录的偏移地址
*
* @var int
*/

var $lastip;

/**
* IP记录的总条数(不包含版本信息记录)
*
* @var int
*/

var $totalip;

/**
* 返回读取的长整型数
*
* @access private
* @return int
*/

function getlong() {
       //将读取的little-endian编码的4个字节转化为长整型数
       $result = unpack('Vlong', fread($this->fp, 4));
       return $result['long'];
}

/**
* 返回读取的3个字节的长整型数
*
* @access private
* @return int
*/

function getlong3() {
       //将读取的little-endian编码的3个字节转化为长整型数
       $result = unpack('Vlong', fread($this->fp, 3).chr(0));
       return $result['long'];
}

/**
* 返回压缩后可进行比较的IP地址
*
* @access private
* @param string $ip
* @return string
*/

function packip($ip) {
       // 将IP地址转化为长整型数,如果在PHP5中,IP地址错误,则返回False,
       // 这时intval将Flase转化为整数-1,之后压缩成big-endian编码的字符串
       return pack('N', intval(ip2long($ip)));
}

/**
* 返回读取的字符串
*
* @access private
* @param string $data
* @return string
*/

function getstring($data = "") {
       $char = fread($this->fp, 1);
       while (ord($char) > 0) { // 字符串按照C格式保存,以\0结束
              $data .= $char; // 将读取的字符连接到给定字符串之后
              $char = fread($this->fp, 1);
       }
       return $data;
}

/**
* 返回地区信息
*
* @access private
* @return string
*/

function getarea() {
       $byte = fread($this->fp, 1); // 标志字节
       switch (ord($byte)) {
              case 0: // 没有区域信息
                     $area = "";
                     break;
              case 1:
              case 2: // 标志字节为1或2,表示区域信息被重定向
                     fseek($this->fp, $this->getlong3());
                     $area = $this->getstring();
                     break;
              default: // 否则,表示区域信息没有被重定向
                     $area = $this->getstring($byte);
                     break;
       }
       return $area;
}

/**
* 根据所给 IP 地址或域名返回所在地区信息
*
* @access public
* @param string $ip
* @return array
*/

function getlocation($ip) {
       if (!$this->fp) return null; // 如果数据文件没有被正确打开,则直接返回空
       $location['ip'] = gethostbyname($ip); // 将输入的域名转化为IP地址
       $ip = $this->packip($location['ip']); // 将输入的IP地址转化为可比较的IP地址
       // 不合法的IP地址会被转化为255.255.255.255
       // 对分搜索
       $l = 0; // 搜索的下边界
       $u = $this->totalip; // 搜索的上边界
       $findip = $this->lastip; // 如果没有找到就返回最后一条IP记录(QQWry.Dat的版本信息)
       while ($l <= $u) { // 当上边界小于下边界时,查找失败
              $i = floor(($l + $u) / 2); // 计算近似中间记录
              fseek($this->fp, $this->firstip + $i * 7);
              $beginip = strrev(fread($this->fp, 4)); // 获取中间记录的开始IP地址
              // strrev函数在这里的作用是将little-endian的压缩IP地址转化为big-endian的格式
              // 以便用于比较,后面相同。
              if ($ip < $beginip) { // 用户的IP小于中间记录的开始IP地址时
                     $u = $i - 1; // 将搜索的上边界修改为中间记录减一
              } else {
                     fseek($this->fp, $this->getlong3());
                     $endip = strrev(fread($this->fp, 4)); // 获取中间记录的结束IP地址
                     if ($ip > $endip) { // 用户的IP大于中间记录的结束IP地址时
                            $l = $i + 1; // 将搜索的下边界修改为中间记录加一
                     }
                     else { // 用户的IP在中间记录的IP范围内时
                            $findip = $this->firstip + $i * 7;
                            break; // 则表示找到结果,退出循环
                     }
              }
       }
       //获取查找到的IP地理位置信息
       fseek($this->fp, $findip);
       $location['beginip'] = long2ip($this->getlong()); // 用户IP所在范围的开始地址
       $offset = $this->getlong3();
       fseek($this->fp, $offset);
       $location['endip'] = long2ip($this->getlong()); // 用户IP所在范围的结束地址
       $byte = fread($this->fp, 1); // 标志字节
       switch (ord($byte)) {
              case 1: // 标志字节为1,表示国家和区域信息都被同时重定向
                     $countryOffset = $this->getlong3(); // 重定向地址
                     fseek($this->fp, $countryOffset);
                     $byte = fread($this->fp, 1); // 标志字节
                     switch (ord($byte)) {
                            case 2: // 标志字节为2,表示国家信息又被重定向
                                   fseek($this->fp, $this->getlong3());
                                   $location['country'] = $this->getstring();
                                   fseek($this->fp, $countryOffset + 4);
                                   $location['area'] = $this->getarea();
                                   break;
                            default: // 否则,表示国家信息没有被重定向
                                   $location['country'] = $this->getstring($byte);
                                   $location['area'] = $this->getarea();
                                   break;
                     }
                     break;

              case 2: // 标志字节为2,表示国家信息被重定向
                     fseek($this->fp, $this->getlong3());
                     $location['country'] = $this->getstring();
                     fseek($this->fp, $offset + 8);
                     $location['area'] = $this->getarea();
                     break;

              default: // 否则,表示国家信息没有被重定向
                     $location['country'] = $this->getstring($byte);
                     $location['area'] = $this->getarea();
                     break;
       }
       if ($location['country'] == " CZ88.NET") { // CZ88.NET表示没有有效信息
              $location['country'] = "未知";
       }
       if ($location['area'] == " CZ88.NET") {
              $location['area'] = "";
       }
       return $location;
}

/**
* 构造函数,打开 QQWry.Dat 文件并初始化类中的信息
*
* @param string $filename
* @return IpLocation
*/

function IpLocation($filename = "QQWry.Dat") {
       if (($this->fp = @fopen($filename, 'rb')) !== false) {
              $this->firstip = $this->getlong();
              $this->lastip = $this->getlong();
              $this->totalip = ($this->lastip - $this->firstip) / 7;
              //注册析构函数,使其在程序执行结束时执行
              register_shutdown_function(array(&$this, '_IpLocation'));
       }
}

/**
* 析构函数,用于在页面执行结束后自动关闭打开的文件。
*
*/

function _IpLocation() {
       fclose($this->fp);
}

}//end of class
?>
怎么单独限制 ”日本“ 的
创想 www.itcly.cn

TOP

引用:
原帖由 alone7 于 2009-11-3 19:04 发表
怎么单独限制 ”日本“ 的
知道ip段就判断呗
阿权的书房:摄影/杂记/PHP/Linux
http://www.asLibra.com

TOP

网上有个GEOIP的类库
你可以看下
http://weibin.og

TOP