In short: if the user does not want this, you will never know where he is from. However, a more βreliableβ solution would be to add a referrer to the link from the source site to yours. Sort of
<a href="http://example.com/index.php?referrer=originId">Visit example.com</a>
This requires that external sites cannot just link to your site, but you always need to add your personal identifier. If this is not possible, you cannot do anything.
It is possible that someone could change this identifier too.
source share