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.