Member Avatar for diafol

OK I think I get the problem. You have to be careful with the version of the DB you download. I downloaded the full DB - but this is not free and is encoded! You need to download this file: http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/ .

It is a gunzip file, which you need to extract the file GeoIP.dat. If you can't do this, download a free extractor called 7-zip from http://www.7-zip.org/ .

Place the extracted file into a folder called "geoinc". Into that folder also include the file geoip.inc. I renamed the file to geoip.inc.php.

This code now works for me:

<?php
include("{$_SERVER['DOCUMENT_ROOT']}/geoinc/geoip.inc.php");

$gi = geoip_open("{$_SERVER['DOCUMENT_ROOT']}/geoinc/GeoIP.dat",GEOIP_STANDARD);
echo geoip_country_code_by_addr($gi, "24.24.24.24") . "\t" .
     geoip_country_name_by_addr($gi, "24.24.24.24") . "\n";
echo geoip_country_code_by_addr($gi, "80.24.24.24") . "\t" .
     geoip_country_name_by_addr($gi, "80.24.24.24") . "\n";
geoip_close($gi);
?>

I get the output:

US United States ES Spain

Just do this to get the code and country of an user:

<?php
include("{$_SERVER['DOCUMENT_ROOT']}/geoinc/geoip.inc.php");
$gi = geoip_open("{$_SERVER['DOCUMENT_ROOT']}/geoinc/GeoIP.dat",GEOIP_STANDARD);
echo geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']) . "\t" .
     geoip_country_name_by_addr($gi, $_SERVER['REMOTE_ADDR']) . "\n";
geoip_close($gi);
?>

Just be aware, if you're testing this on localhost, the code won't work because the $_SERVER will return "127.0.0.1", which obviously does not have a country.

Reference to GeoIp what does it do is it a Proxy bypass or what i need to be clear before i can come in please some one should explaint to me

Member Avatar for diafol

GeoIP = functions and a db file. The functions return the country code or the country name, based on the user's remote address (IP).

This does not involve proxies.

You can use the function output to redirect or refuse entry to users from specific countries.

I have a router and I think it is not a problem to show my real IP

Member Avatar for diafol

Do you have a problem or does it work for you. If OK, mark this solved, otherwise tell me the problem.

Unfortunately does not work.
Prepared to explain what I do. Put this code

<?php
include("{$_SERVER['DOCUMENT_ROOT']}/geoinc/geoip.inc.php");

$gi = geoip_open("{$_SERVER['DOCUMENT_ROOT']}/geoinc/GeoIP.dat",GEOIP_STANDARD);
echo geoip_country_code_by_addr($gi, "24.24.24.24") . "\t" .
     geoip_country_name_by_addr($gi, "24.24.24.24") . "\n";
echo geoip_country_code_by_addr($gi, "80.24.24.24") . "\t" .
     geoip_country_name_by_addr($gi, "80.24.24.24") . "\n";
geoip_close($gi);
?>

You can look through here and the Mozilla source code
http://answer23.100free.com/
Look and write me where wrong.
I put geo.inc.php and Geoip.dat in geoinc
Thank you

Member Avatar for diafol
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html> 
<head> 
<title>Untitled</title> 
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"> 
<meta name="generator" content="Web Page Maker"> 
 
<style type="text/css"> 
 ... just styles in here took them out for now ...
</style> 
</head> 
<body bgColor="#000000"> 
<div id="container"> 
  <div id="image1" style="position:absolute; overflow:hidden; left:0px; top:173px; width:300px; height:300px; z-index:0">
     <img src="images/puma.gif" alt="" title="" border=0 width=300 height=300>
  </div> 
  <div id="html1" style="position:absolute; overflow:hidden; left:379px; top:177px; width:200px; height:125px; z-index:1"> 
  </div> 
</div>
</body> 
</html>

As you can see - this does not show any html output by the php script.

Can I suggest that you change that you change <body bgColor="#000000"> to <body> for now so that you can see any text that php outputs.

Please place

<?php
  echo "Sono qui!";
?>

or something similar anywhere after the body tag and look at it again. Does it show?

Member Avatar for diafol

First off, if you did as I suggested, the php doesn't seem to be working.

You should see 'Sono qui!' on the page, but you don't - is this page called index.php?

I noticed that the hosting problem on php and tried to post another hosting and I have already shown

<html>
 <head>
  <title>PHP Test</title>
 </head>
 <body>
 <?php
  echo "Sono qui!";
?>
 </body>
</html>

Now where should I write to ask the other code in the continuation of this.
Thank you

Member Avatar for diafol

OK, I thought something was wrong.

<?php
include("{$_SERVER['DOCUMENT_ROOT']}/geoinc/geoip.inc.php");
$gi = geoip_open("{$_SERVER['DOCUMENT_ROOT']}/geoinc/GeoIP.dat",GEOIP_STANDARD);
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html> 
<head> 
<title>Untitled</title> 
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"> 
<meta name="generator" content="Web Page Maker"> 
 
<style type="text/css"> 
 ... just styles in here took them out for now ...
</style> 
</head> 
<body bgColor="#000000"> 
<div id="container"> 

<?php
echo geoip_country_code_by_addr($gi, "24.24.24.24") . "\t" .
     geoip_country_name_by_addr($gi, "24.24.24.24") . "\n";
echo geoip_country_code_by_addr($gi, "80.24.24.24") . "\t" .
     geoip_country_name_by_addr($gi, "80.24.24.24") . "\n";
geoip_close($gi);
?>

  <div id="image1" style="position:absolute; overflow:hidden; left:0px; top:173px; width:300px; height:300px; z-index:0">
     <img src="images/puma.gif" alt="" title="" border=0 width=300 height=300>
  </div> 
  <div id="html1" style="position:absolute; overflow:hidden; left:379px; top:177px; width:200px; height:125px; z-index:1"> 
  </div> 
</div>
</body> 
</html>

This should work if you can get php to output text to the screen.

I put your code and give me error

Warning: include(/home/new/public_html/geoinc/geoip.inc.php) [function.include]: failed to open stream: No such file or directory in /home/new/public_html/test.php on line 2

Warning: include() [function.include]: Failed opening '/home/new/public_html/geoinc/geoip.inc.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/new/public_html/test.php on line 2

Fatal error: Call to undefined function geoip_open() in /home/new/public_html/test.php on line 3

Member Avatar for diafol

You have not got the geoip.inc.php file in the geoinc folder. Copy the file to that folder. Ensure you also have the GeoIP.dat file too.

in the folder are not know why not distinguishes. At the moment I got to host so it began to be tested. Please tell me if this link http://api.hostip.info/country.php?ip which distinguishes state can be useful

Member Avatar for diafol

in the folder are not know why not distinguishes. At the moment I got to host so it began to be tested. Please tell me if this link http://api.hostip.info/country.php?ip which distinguishes state can be useful

This seems to work - I get 'UK' on the page.

Okay. Please Define me a php code which can be set up on my page to see if it will work on the new host.
Thank You

Member Avatar for diafol

I've already done this. Do this again.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html> 
<head> 
<title>Untitled</title> 
</head> 
<body> 
<?php
  include("{$_SERVER['DOCUMENT_ROOT']}/geoinc/geoip.inc.php");
  $gi = geoip_open("{$_SERVER['DOCUMENT_ROOT']}/geoinc/GeoIP.dat",GEOIP_STANDARD);
echo geoip_country_code_by_addr($gi, "24.24.24.24") . "\t" .
     geoip_country_name_by_addr($gi, "24.24.24.24") . "\n";
echo geoip_country_code_by_addr($gi, "80.24.24.24") . "\t" .
     geoip_country_name_by_addr($gi, "80.24.24.24") . "\n";
geoip_close($gi);
?>
</body> 
</html>

Look, if you've uploaded the geoip.inc.php and GeoIP.dat files to the geoinc folder and you run the code above, you should be OK.

I don't know what more I can do to help.

OK, but that IP can write like this or should not remain

echo geoip_country_code_by_addr($gi, "24.24.24.24") . "\t" .
     geoip_country_name_by_addr($gi, "24.24.24.24") . "\n";
echo geoip_country_code_by_addr($gi, "80.24.24.24") . "\t" .
     geoip_country_name_by_addr($gi, "80.24.24.24") . "\n";
geoip_close($gi);

Thank you

Member Avatar for diafol

OK, but that IP can write like this or should not remain

I don't understand

Member Avatar for diafol
echo geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']) . "<br />" .
     geoip_country_name_by_addr($gi,  $_SERVER['REMOTE_ADDR']);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.