CoPilot

SpaceshipSpaceship
Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
Watch

dna

Top Member
Impact
2,750
Copilot is great...I mostly use it for programming. I once asked Copilot this question.

Can PHP use the IP address of a visitor to my web site to tell me the referring link?

And Copilot's answer:

Yes, PHP can use the IP address of a visitor to your website to tell you the referring link. You can use the $_SERVER['HTTP_REFERER'] variable to get the referring link. However, this method is not reliable as it can be easily spoofed by the user 123.

To get the real IP address of a visitor, you can use the $_SERVER['REMOTE_ADDR'] variable. However, this method is not foolproof either, as it can be masked by proxies or VPNs 14.

If you want to get the real IP address of a visitor even when they are using a proxy, you can use the following PHP code:

PHP

function getUserIP () {
if ( array_key_exists ('HTTP_X_FORWARDED_FOR', $_SERVER) && !empty ($_SERVER ['HTTP_X_FORWARDED_FOR']) ) {
if (strpos ($_SERVER ['HTTP_X_FORWARDED_FOR'], ',')>0) {
$addr = explode (",",$_SERVER ['HTTP_X_FORWARDED_FOR']);
return trim ($addr [0]);
} else {
return $_SERVER ['HTTP_X_FORWARDED_FOR'];
}
} else {
return $_SERVER ['REMOTE_ADDR'];
}
}

$user_ip = getUserIP ();
echo $user_ip; // Output IP address [Ex: 177.87.193.134]


https://stackoverflow.com/questions/13646690/how-to-get-real-ip-from-visitor

https://webmasters.stackexchange.co...isitors-ip-addresses-if-so-what-precautions-c

https://www.educative.io/answers/how-to-get-the-ip-address-of-visitors-on-your-php-powered-website

https://stackoverflow.com/questions/8687642/how-to-detect-the-visitors-ip-address-using-html
 
Last edited:
10
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Appraise.net

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Search: choose where to search from the All tab
Open the search at the top of any page. On the All tab, the list next to the search box lets you choose where to search: everything, all...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back