Overview
- Release Notes and Announcements
- Product Introduction
- Purchase Guide
- Billing Overview
- Basic Service Fees
- Value-added Service Fees
- Related Tencent Cloud Services
- Extra Package Description (Prepaid)
- Subscriptions
- Renewals
- Overdue and Expiration Policies
- Refund Policy
- Usage Cap Policy
- EdgeOne Plan Upgrade Guide
- Comparison of EdgeOne Plans
- Billing Usage
- About "clean traffic" billing instructions
- Getting Started
- Domain Service
- Hosting DNS Records
- Domain Connection
- HTTPS Certificate
- Domain alias
- Traffic Scheduling
- Site Acceleration
- Overview
- Access Control
- Smart Acceleration
- Cache Configuration
- Overview
- EdgeOne Cache Rules
- Cache Configuration
- Clear and Preheat Cach
- How to improve the Cache Hit Rate of EdgeOne
- File Optimization
- Media processing
- Network Optimization
- HTTP/2
- HTTP/3(QUIC)
- Overview
- Enable HTTP/3
- QUIC SDK
- SDK Overview
- SDK Download and Integration
- Sample Code
- API Documentation
- IPv6 Access
- Maximum Upload Size
- WebSocket
- Client IP Geolocation Header
- Client IP Geographical Location
- gRPC
- URL Rewrite
- Modifying Header
- Custom Error Page
- Request and Response Actions
- Origin Configuration
- Load Balancing
- Origin Group Configuration
- Origin-pull configuration
- Related References
- Collect EdgeOne origin-pull node IP
- Edge Functions
- Overview
- Getting Started
- Operation Guide
- Runtime APIs
- Sample Functions
- Returning an HTML Page
- Returning a JSON Object
- Fetch Remote Resources
- Authenticating a Request Header
- Modifying a Response Header
- Performing an A/B Test
- Setting Cookies
- Performing Redirect Based on the Request Location
- Using the Cache API
- Caching POST Requests
- Responding in Streaming Mode
- Merging Resources and Responding in Streaming Mode
- Protecting Data from Tampering
- Rewriting a m3u8 File and Configuring Authentication
- Adaptive Image Resize
- Image Adaptive WebP
- Customize Referer restriction rules
- Remote Authentication
- HMAC Digital Signature
- Naming a Downloaded File
- Obtaining Client IP Address
- Best Practices
- Security Protection
- Overview
- DDoS Protection
- DDoS Protection Overview
- Exclusive DDoS Protection Usage
- Configuration of Exclusive DDoS protection Rules
- Web Protection
- Bot Management
- Rules Template
- IP and IP Segment Grouping
- Origin Protection
- Custom Response Page
- Alarm Notification
- Rule Engine
- L4 Proxy
- Data Analysis&Log Service
- Log Service
- Overview
- Real-time Logs
- Offline Logs
- Related References
- Data Analysis
- Analytics
- Tool Guide
- Practical Tutorial
- API Documentation
- History
- Introduction
- API Category
- Making API Requests
- Site APIs
- Acceleration Domain Management APIs
- Site Acceleration Configuration APIs
- Alias Domain APIs
- Security Configuration APIs
- Layer 4 Application Proxy APIs
- CreateL4Proxy
- ModifyL4Proxy
- ModifyL4ProxyStatus
- DescribeL4Proxy
- DeleteL4Proxy
- CreateL4ProxyRules
- ModifyL4ProxyRules
- ModifyL4ProxyRulesStatus
- DescribeL4ProxyRules
- DeleteL4ProxyRules
- CreateApplicationProxy
- ModifyApplicationProxy
- ModifyApplicationProxyStatus
- DescribeApplicationProxies
- DeleteApplicationProxy
- CreateApplicationProxyRule
- ModifyApplicationProxyRule
- ModifyApplicationProxyRuleStatus
- DeleteApplicationProxyRule
- Content Management APIs
- Data Analysis APIs
- Log Service APIs
- Billing APIs
- Certificate APIs
- Load Balancing APIs
- Custom Response Page APIs
- Diagnostic Tool APIs
- Version Management APIs
- Data Types
- Error Codes
- FAQs
- Agreements
- TEO Policy
- Contact Us
- Glossary
Menu
Obtaining Client IP Address
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 headerconst ip = request.headers.get('EO-Client-IP') || '';// Respond with JSON datareturn 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. ![](https://cloudcache.intl.tencent-cloud.com/cms/backend-cms/87cc603689e211ee9cb9525400fc26b2.png)
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: ![](https://cloudcache.intl.tencent-cloud.com/cms/backend-cms/1a2c12d089e211ee8fb75254000524f8.png)