Introduced in SQLPage 0.33.0.
Returns the IP address of the client making the HTTP request.
Example
insert into connection_log (client_ip) values (sqlpage.client_ip());
Details
The function returns:
- The IP address of the client as a string
null
if the client IP cannot be determined (e.g., when serving through a Unix socket)
⚠️ Important Notes for Production Use
When running behind a reverse proxy (e.g., Nginx, Apache, Cloudflare):
- This function will return the IP address of the reverse proxy, not the actual client
- To get the real client IP, use
sqlpage.header
:sqlpage.header('x-forwarded-for')
orsqlpage.header('x-real-ip')
- The exact header name depends on your reverse proxy configuration
Example with reverse proxy:
-- Choose the appropriate header based on your setup
select coalesce(
sqlpage.header('x-forwarded-for'),
sqlpage.header('x-real-ip'),
sqlpage.client_ip()
) as real_client_ip;
For security-critical applications, ensure your reverse proxy is properly configured to set and validate these headers.
basic_auth_password
basic_auth_username
client_ip
cookie
current_working_directory
environment_variable
exec
fetch
fetch_with_meta
hash_password
header
headers
link
path
persist_uploaded_file
protocol
random_string
read_file_as_data_url
read_file_as_text
request_body
request_body_base64
request_method
run_sql
uploaded_file_mime_type
uploaded_file_name
uploaded_file_path
url_encode
variables
version