ampproject / ampproject/amphtml

New header/key to get IP address of client at backend for the requests made via AMP email

Open
#33,431 1 comment 0 reactions 0 assignees View on GitHub
Stale Type: Feature Request
Dominant language
JavaScript
Stars
14.9k
Forks
4.1k
PR merge metrics
No merged PRs in 30d

Description

## Problem Statement

I used to do tracking for user's IP address for submission done via web form, but when I have integrated AMP-EMAIL, the IP I am getting at the backend is of google's server. So I am not able to track the user's IP anymore. It's an important attribute for me.

Also, I am not able to find any IP-related documentation for `amp-email`.

## Possible solution

When google transfers `amp-form` data to the backend server, it can send a new HTTP Header or a fixed `$_POST` key containing the client's IP address.

## Things I have tried

Below is the code I am using to get IP as of now, but not able to get client IP in any of the $_SERVER key:

```php
function get_ip_address()
{
$str="";
foreach (array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR') as $key){
if (array_key_exists($key, $_SERVER) === true)
{
foreach (explode(',', $_SERVER[$key]) as $ip)
{
$ip = trim($ip); // just to be safe

if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false)
{
$str .= $key." => ".$ip." ";;
}
}
}
}
return $str;
}
```

[Stackoverflow Question: How to get IP address of client in PHP for the requests made via AMP email](https://stackoverflow.com/questions/66763082/how-to-get-ip-address-of-client-in-php-for-the-requests-made-via-amp-email)

Contributor guide

Open the contributing guide

Research direction

No source file, test, or entry point is named. Start by reviewing how AMP Email amp-form requests reach the backend and the related IP-address documentation; the issue is done only when the project has an agreed, documented way to provide the client IP or clearly explains why it cannot.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, php
Domain
api, backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.