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 really what I want. See 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 wish to do is when the user enters the page of my site, and enter the data that will be requested. that the query be executed, and show that this was done perhaps by his IP or a point near it.
I’ve tried many ways, but without success.
I doubt why it doesn’t work when I put it in the proxy: $_SERVER['REMOTE_ADDR']
and at the door: $_SERVER['REMOTE_PORT']
?
In my view this would be requesting his ip plus the port, only when I try to use, it does not work. How can I achieve this?
Thanks for the answers, but this function of discovering the IP can already 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 don’t know if it’s something simple, but I’m looking for it in time is how do I deploy it 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 that line:
curl_setopt($c, CURLOPT_PROXY, $proxy);
But even if I change $proxy
for $ip
, still not sure. I have read all the links that were passed as well, and I did many more tests yet unsuccessfully.
I believe that that site you passed as an example goes against accepted rules in the community. I removed from your question.
– MarceloBoni