Try $_SERVER['HTTP_REFERER'] to get the page users come from.
I don't exactly remember but it doesn't work in every circumstances, like with frames there is a strange behaviour I can't remember. But i helps...
actually it's
$HTTP_REFERER
or $HTTP_SERVER_VARS['HTTP_REFERER']
or $_SERVER['HTTP_REFERER']