Use IP or LOCAL that the user is (or closest to) to send a query [duplicate]

2

I have the following code:

function getpage($url, $postdata=''){
    $c = curl_init(); <br>
    curl_setopt($c, CURLOPT_URL, $url); 
    curl_setopt($c, CURLOPT_SSL_VERIFYPEER,false); 
    curl_setopt($c, CURLOPT_SSL_VERIFYHOST,false); 

    curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($c, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1)
    AppleWebKit/537.2 (KHTML, like Gecko) Chrome/22.0.1216.0 Safari/537.2'); 
    curl_setopt($c, CURLOPT_POST, 1); <br>
    curl_setopt($c, CURLOPT_POSTFIELDS, $postdata);

What happens is that I can even use a proxy, but that's not quite what I want. Here's how it would look with proxy:

   function getpage($url, $postdata=''){
   $proxy = 'UM-IP';
   $porta = 'A-PORTA';
   $c = curl_init();
   curl_setopt($c, CURLOPT_URL, $url);
   curl_setopt($c, CURLOPT_PROXY, $proxy);
   curl_setopt($c, CURLOPT_PROXYPORT, $porta);
   curl_setopt($c, CURLOPT_SSL_VERIFYPEER,false);
   curl_setopt($c, CURLOPT_SSL_VERIFYHOST,false);

   curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1);
   curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($c, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1) 
   AppleWebKit/537.2 (KHTML, like Gecko) Chrome/22.0.1216.0 Safari/537.2'); 
   curl_setopt($c, CURLOPT_POST, 1);
   curl_setopt($c, CURLOPT_POSTFIELDS, $postdata);

What I want to do is when the user enters the page of my site, and enter the data that will be requested. that the query is executed, and show that this was done perhaps by his IP or from a point near him.

I have tried many forms, but to no avail.

I'm wondering why it does not work when I put it in the proxy: $_SERVER['REMOTE_ADDR'] and on the port: $_SERVER['REMOTE_PORT'] ?

In my view this would be asking for his ip plus the port, but when I try to use it, it does not work. How can I achieve this?

Thanks for the answers, but this function of discovering the IP already can easily with these codes:

function getpage($url, $postdata='')  
{  
    if (!empty($_SERVER['HTTP_CLIENT_IP'])) {  
    $ip = $_SERVER['HTTP_CLIENT_IP'];  
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {  
    $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];  
} else {  
    $ip = $_SERVER['REMOTE_ADDR'];  
}  
echo $ip;

What I need now, I do not know if it's something simple, but I'm looking for the time, how do I deploy correctly in the code I have:

$c = curl_init();  
curl_setopt($c, CURLOPT_URL, $url);  
curl_setopt($c, CURLOPT_PROXY, $proxy);  
curl_setopt($c, CURLOPT_SSL_VERIFYPEER,false);  
curl_setopt($c, CURLOPT_SSL_VERIFYHOST,false);  
curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1);  
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);  
curl_setopt($c, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1)   AppleWebKit/537.2 (KHTML, like Gecko) Chrome/22.0.1216.0 Safari/537.2');  
curl_setopt($c, CURLOPT_POST, 1);  
curl_setopt($c, CURLOPT_POSTFIELDS, $postdata);  

Maybe this line:

curl_setopt($c, CURLOPT_PROXY, $proxy);  

But even though I change $proxy to $ip , it still does not work. I have read all the links that have been passed too, and have done many more tests without success.

    
asked by anonymous 19.07.2017 / 08:31

2 answers

0
// Função para obter o IP PHP
function get_client_ip() {
    $ipaddress = '';
    if (getenv('HTTP_CLIENT_IP'))
        $ipaddress = getenv('HTTP_CLIENT_IP');
    else if(getenv('HTTP_X_FORWARDED_FOR'))
        $ipaddress = getenv('HTTP_X_FORWARDED_FOR');
    else if(getenv('HTTP_X_FORWARDED'))
        $ipaddress = getenv('HTTP_X_FORWARDED');
    else if(getenv('HTTP_FORWARDED_FOR'))
        $ipaddress = getenv('HTTP_FORWARDED_FOR');
    else if(getenv('HTTP_FORWARDED'))
        $ipaddress = getenv('HTTP_FORWARDED');
    else if(getenv('REMOTE_ADDR'))
        $ipaddress = getenv('REMOTE_ADDR');
    else
        $ipaddress = 'UNKNOWN';
    return $ipaddress;
}

//Server para obter IP do Cliente
function get_client_ip() {
$ipaddress = '';
if (isset($_SERVER['HTTP_CLIENT_IP']))
    $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
else if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
    $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
else if(isset($_SERVER['HTTP_X_FORWARDED']))
    $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
else if(isset($_SERVER['HTTP_FORWARDED_FOR']))
    $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
else if(isset($_SERVER['HTTP_FORWARDED']))
    $ipaddress = $_SERVER['HTTP_FORWARDED'];
else if(isset($_SERVER['REMOTE_ADDR']))
    $ipaddress = $_SERVER['REMOTE_ADDR'];
else
    $ipaddress = 'UNKNOWN';
return $ipaddress;
}

I had this function for an identical situation and it worked for me, I hope you can too.

    
19.07.2017 / 11:28
0

It's exactly the same as this one. What you want to do is not possible, at least you can not just a mere website. In addition to security holes in the code, but I'll ignore this.

In order for you to use some IP as a proxy it must be a proxy , ie it must be a server proxy server. Many malware even do this just for that infected device to serve as a proxy.

In general it's the same as I get your IP and want to http://(seu-ip) and wait for a site to open, this will work only if your IP has some HTTP server connected, at most it will give connection error to your IP using HTTP .

If it were not so then anyone could spoof an IP by simply using a proxy as a proxy.

What do they do?

Simple, hire proxy servers around the world and use the proxy closest to the person's location or hire servers and install a Squid . Another option is to create software installable on the client machine (a smartphone application and a program installable on the PC) that can execute such a request, logically it will depart using the client IP.

>

There are several and several companies that sell proxies around the world, for example:

There are also services known as "backconnect proxies", they are residential network IPs, usually originating from the botnet, there is no way to know the source of these IPs and those servers. They also change the IP every X minutes most of the time, they are:

  

I have no link to any site mentioned above!

The other solution, as I mentioned, is to have your own proxy server, for example using Squid , so just hire dedicated servers around the world and install the software. Now in cURL you will be able to connect to it and use it as a proxy, logically requires some settings .

    
19.07.2017 / 15:05