When the browser sends header info to the server, $_SERVER[\'HTTP_REFERER\'] should give us the previous page URL right?
What returns from $_SERVE
$_SERVER is a global array variable, and the referrer value is an element of the array with key HTTP_REFERER. If is no referrer header is sent by the browser, then the element is simply missing from the array. You can check whether an array has an element with array_key_exists; in this case:
array_key_exists('HTTP_REFERER', $_SERVER)