Development

#2798 (Get Local / Remote Ip address from Request?)

You must first sign up to be able to contribute.

Ticket #2798 (closed enhancement: fixed)

Opened 1 year ago

Last modified 2 months ago

Get Local / Remote Ip address from Request?

Reported by: upandhigh Assigned to: fabien
Priority: major Milestone: 1.2.0 RC1
Component: controller Version: 1.0.10
Keywords: Cc:
Qualification: Accepted

Description

Hi,

you have in your Book this desc:

You don't have to worry about whether your server supports the $_SERVER or the $_ENV variables, or about default values or server-compatibility issues--the sfWebRequest methods do it all for you. Besides, their names are so evident that you will no longer need to browse the PHP documentation to find out how to get information from the request.

But You have no methods to get Remote / Local IP Address. So why not implement it?

Two new methods will be great:

1) Getting Remote Ip
2) Getting Local Ip's from X-Forwarder

Here is related topic on your forum: http://www.symfony-project.org/forum/index.php/t/7875/

Attachments

x_forwarded_for.patch (2.7 kB) - added by Nebelmann on 11/02/08 21:00:49.
This patch should do the trick. ->getForwardedRemoteAddress() is now ->getForwardedFor(), and returns an array or null.

Change History

06/23/08 07:02:59 changed by dwhittle

  • qualification changed from Unreviewed to Accepted.
  • milestone set to 1.0.17.

06/24/08 11:24:45 changed by hartym

I think this cannot be implemented in 1.0, as it is a new feature.

Maybe milestone should be changed to 1.1 or 1.2?

06/24/08 11:43:40 changed by fabien

  • milestone changed from 1.0.17 to 1.2.0.

This is indeed a new feature.

07/02/08 09:43:58 changed by Carl.Vondrick

  • status changed from new to closed.
  • resolution set to fixed.

(In [10060]) 1.2: added ->getRemoteAddress() to get the client's IP address and ->getForwardedRemoteAddress() to get the IP address from behind a proxy (closes #2798)

Note: I am not sure if ->getForwardedRemoteAddress() is the best method name. Welcome to suggestions in ticket #2798.

07/07/08 16:39:16 changed by upandhigh

  • priority changed from minor to major.
  • status changed from closed to reopened.
  • resolution deleted.

I'am very sorry for delay, but some comments:

Http forwarded can include not only ONE ip address, so:

HTTP_X_FORWARDED_FOR = IPaddress1, IPaddress2

is normal situation. and these IP's are not obviously remote, often they are LOCAL network ip's - so ForwardedRemoteAddress? is not really good name for this.

also one more thing, in modern web server patterns usual situation when SYMFONY is on the backend server, and on frontend is something lighty like nginx or lighttpd, just to handle connections.

in this way, HTTP ENV will have 3 IP sets

HTTP_X-REAL-IP - Real user IP, this var is defined in FRONTEND httpd server, so it can have any NAME but now it's X-REAL-IP.
HTTP_REMOTE_ADDR - IP address of FRONTEND SERVER from where request was sent to backend one
X_FORWARDED_FOR - this go unchanged or sometimes pipls useing it instead of HTTP_X-REAL-IP in frontend config, by just adding new REAL ip as first one in this list

so as you can see, REMOTE_ADDR can be "moved" to some other variable - like HTTP_X-REAL-IP, and the meaning of REMOTE_ADDR will be changed - so your getRemoteAddr() will return not user IP, but IP of frontend server. so the great IDEA to define the name of USER ip somewhere in the configs - what you think about that?

So in one of YAML file, we can set - variable name, what include CLIENT IP address, and after that getRemoteAddr - will return ip from this variable, if it's DEFINED, if nope - then from HTTP_REMOTE_ADDR. and about the names ;)

ofcourse getForwardedRemoteAddress() looks not elegant at all :-((( some my suggestions you maybe will choose:

->getRemoteAddr();
->getForwardedAddr();
->getRemoteAddr();
->getXForwardedFor();
->getRemoteIp();
->getLocalIp();
->getIp(); // by default will return remote
->getIp("X_FORWARDED");
->getIp("X_FORWARDED_REAL");

or in object style:
->getIp(sfIP::X-REAL-IP);
->getIp(sfIP::FORWARDED);

11/02/08 21:00:49 changed by Nebelmann

  • attachment x_forwarded_for.patch added.

This patch should do the trick. ->getForwardedRemoteAddress() is now ->getForwardedFor(), and returns an array or null.

11/15/08 22:12:39 changed by FabianLange

  • status changed from reopened to closed.
  • resolution set to fixed.

(In [13018]) [1.2] fixed #2798 by applying Patch from Nebelmann

11/15/08 22:13:01 changed by FabianLange

  • milestone changed from 1.2.0 to 1.2.0 RC1.