user3196950
user3196950

Reputation: 43

Capture X-FORWARDED-FOR header via htaccess?

I'm running my site on a shared server and want to be able to capture the "real" ip address of users who are using the Puffin browser. Puffin renders web site content on its own cloud servers and then passes the result to the user's browser. The downside is that the user's ip address appears as that of the Puffin cloud server and not their own. Puffin does however pass the "real" ip address using the X-FORWARDED-FOR header. Unfortunately my host provider strips this out.

I asked them if there was any way round this and they have responded saying (regarding the X-FORWARDED-FOR header):

"You may be able to capture this with an environment variable within a .htaccess file."

At this point I'm way out of my depth so I was wondering if anyone could explain in simple terms how to go about this?

Upvotes: 4

Views: 3260

Answers (1)

Jon Lin
Jon Lin

Reputation: 143906

If they strip out the header, you may not even be able to capture it in your htaccess file. But you'd need something that looks like this:

RewriteEngine On
RewriteCond %{HTTP:X-FORWARDED-FOR} ^(.+)$
RewriteRule ^ - [L,E=X-FORWARDED:%1]

And you'd be able to get the environment variable via (using php) $_SERVER['X-FORWARDED']

Upvotes: 3

Related Questions