tencent cloud

All product documents
Tencent Cloud EdgeOne
Obtaining Client IP Address
Last updated: 2023-12-13 10:57:07
Obtaining Client IP Address
Last updated: 2023-12-13 10:57:07
Since the front end cannot directly obtain the client IP address, it's often necessary to obtain the client IP address through the server side or third-party services in multiple business scenarios. The client IP address is obtained in this example through client IP header EO-Client-IP activated in the rule engine, and assembled into data in the form of JSON to respond to the clients, which succeeds in obtaining client IP address by the use of edge function.
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request));
});

function handleRequest(request) {
// Obtain the client IP through the EO-Client-IP header
const ip = request.headers.get('EO-Client-IP') || '';
// Respond with JSON data
return new Response(JSON.stringify({ ip }), {
headers: { 'content-type': 'application/json' },
});
}

Sample Preview

Firstly, activate the client IP switch of the domain name that needs to trigger the edge function and set the header name as EO-Client-IP in the Rule Engine configuration.

Once the configuration is effective, enter a URL (such as https://example.com/ip) which matches the trigger rule of the edge function in the address bar of the browser on both the PC and mobile terminal to obtain the client's IP address:


Related References

Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 available.

7x24 Phone Support
Hong Kong, China
+852 800 906 020 (Toll Free)
United States
+1 844 606 0804 (Toll Free)
United Kingdom
+44 808 196 4551 (Toll Free)
Canada
+1 888 605 7930 (Toll Free)
Australia
+61 1300 986 386 (Toll Free)
EdgeOne hotline
+852 300 80699
More local hotlines coming soon