inet_client_addr in PostgreSQL don't return IP
You could abuse the application_name setting to pass the HTTP client IP from PHP to Postgres.

In PHP, once connected:

&lt;? pg_query("SET application_name TO '$_SERVER[REMOTE_ADDR]'"); ?&gt;


Or set it right at connection time with pg_connect which would normally support it in the conninfo string (see Connection Strings in the manual)

In your trigger, use   current_setting('application_name') to retrieve this information,
instead of inet_client_addr() which doesn't do what you want, as already answered.

There should also be a check in the trigger that this value is what you expect before storing it, since the trigger may be fired in any session, not just the ones initiated by PHP.