use user ip as proxy to request

Asked

Viewed 211 times

4

I am developing a site using the guzzle and wanted to use the ip and the port that the user accesses the site as proxy at the time of the request already tried these codes and n was

<?php
$ip = getenv("REMOTE_ADDR");
$porta = getenv("REMOTE_PORT");
$ip2 = $_SERVER['HTTP_X_FORWARDED_FOR'];
require '/php.php';
$body = request("http://www.paodeacucar.com/", $ref, 'GET', ['proxy' => 'http://' . $ip . ':' . $porta]);
echo $body;

1 answer

7


That’s not possible for an obvious reason. If this were possible the practice of IP-Spoofing would be extremely easy, after all you could pass by any IP (and still get the answer on behalf of that IP).

The only way this works is if the client accepts these connections, interprets the request and returns the response to your server, which it will never do by default. After all, it is not a proxy.

The alternatives, which I can think of now, are:

  • Run the code in the browser via Javascript/WASM, assuming the body of the response is significant. However, it is necessary that your site is authorized by CORS, depending on the case. As this request part of the client the IP of it will be used.
  • Run this outside the context of the browser, as an application or executable. In this case you are on the client side, then you can communicate using the user’s IP, without any browser restriction.
  • and how did you do via php to ask this question and if he altorise to use his ip as proxy ? how would this connection be done

  • @Cyberhacker as any other way. For common use (HTTP) is Curl, which has the CURLOPT_PROXY (https://curl.haxx.se/libcurl/c/CURLOPT_PROXY.html).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.