Jump to content

Recommended Posts

Thanks guys , but don't think I explained myself good

 

I did try the IP range but thats too much and don't have that of a big database so I jsut wanted to use showmyip.com as webservice to check the ip I send and recive back the country name

 

$ip=$_SERVER['REMOTE_ADDR'];

$url='http://www.showmyip.com/?ip=';

 

Its just how to actully send it automaticlly when the user logs in the page and then direct him upon finding his country

 

Link to comment
https://forums.phpfreaks.com/topic/44461-ip-localization/#findComment-215931
Share on other sites

Okai gotcha

 

<?php


$ip = addslashes($_SERVER['REMOTE_ADDR']);

// initialise the session, this time with no URL
    $ch = curl_init();
    
    // Setting the URL including the IP
    curl_setopt($ch, CURLOPT_URL, "http://www.showmyip.com/?ip=$ip");
    
    // Return the output from the cURL session rather than displaying in the browser.
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    
    //Executting  the session, returning the results to $country, and close.
    $Country = curl_exec($ch);
    curl_close($ch);
    print "country of $ip: $Country";

?>

 

doesn't return anything :(

Link to comment
https://forums.phpfreaks.com/topic/44461-ip-localization/#findComment-215945
Share on other sites

Should work, maybe you have set the options in the wrong order?

 

$Country, should be $html as CURL will return the raw html of the page.

 

But other than that it should work.

 

You will need to output the HTML and take a look at it in regex buddy to see how to snip out the country code.

 

monk.e.boy

Link to comment
https://forums.phpfreaks.com/topic/44461-ip-localization/#findComment-215957
Share on other sites

okai keep getting this error

 

<?php


$ip = addslashes($_SERVER['REMOTE_ADDR']);

// initialise the session, this time with no URL
    $ch = curl_init();
    
    // Setting the URL including the IP
    curl_setopt($ch, CURLOPT_URL, "http://www.showmyip.com/?ip=$ip");
    
    // Return the output from the cURL session rather than displaying in the browser.
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    
    //Executting  the session, returning the results to $country, and close.
    $html = curl_exec($ch);
    curl_close($ch);
    print "$html";

?>

 

 

Fatal error: Call to undefined function: curl_init() in /home/www/digitall/func_test.php on line 7

Link to comment
https://forums.phpfreaks.com/topic/44461-ip-localization/#findComment-215962
Share on other sites

hey guys cheers for all the input

 

Seems like I don't have cURL installed so I tried MB's idea using fopen

 

 

<?

$ip = addslashes($_SERVER['REMOTE_ADDR']);
$data = fopen("http://www.showmyip.com/?ip=$ip", "r");
print' $data';
?>

 

that returns only $data seems nothing is caputered

but when i try

http://www.showmyip.com/?ip=xxx.xxx.xxx.xxx

it returns all the details so the format is right

 

again thanks

Link to comment
https://forums.phpfreaks.com/topic/44461-ip-localization/#findComment-215975
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.