How to track users origin in PHP , i see people using this ref= often i don't have any idea how does this get request works .
My code
$calling_url = mysql_real_escape_string($_SERVER['HTTP_REFERER']);
How to track users origin in PHP , i see people using this ref= often i don't have any idea how does this get request works .
My code
$calling_url = mysql_real_escape_string($_SERVER['HTTP_REFERER']);
URL:
http://example.com/index.php?ref=http://externalsite.com/page.html OR
http://example.com/index.php?ref=http%3A%2F%2Fexternalsite.com%2Fpage.html
PHP:
$ref = mysql_real_escape_string(rawurldecode($_GET["ref"]));
// $ref will be "http://externalsite.com/page.html" in both cases
Resources for URL tracking:
Without knowing more about what you're trying to achieve.
If users are coming from outside your site, the best bet is to use HTTP_REFERER. If someone asks your server for a page, you'll have to take their word for it as far as the referrer is concerned. Whether that's in the URL or in the browser. If they don't want to tell you, you can't make them.
Even though it's not that reliable it's going to be more reliable than depending on someone else's application. Unless there is a transaction involved that would encourage the referrers to format the url correctly.
If users are moving around within your own site. You can use the ref= strategy, or you can use session variables.