How would you print refering URL in PHP?

echo $HTTP_REFERER ???

Also,

IN a table i have a field called aid.

One URL is http://www.mysite.com/articles.php?aid=a_number

One problem is that, say i type in the number 1, i get the article related to number 1 however if i type in the number, let's say...94...It displays a page, when this record does not exist.

How can i overcome this?