Remember that JavaScript is running on the user's machine once the page is received, while PHP is running on the server before the page contents get sent to the user.
If you can control the pages which are linking to your page, then you can add a query string variable to the link:
<a href="http://www.yoursite.com/page.php[color=red]?referer=www.someothersite.com[/color]">click me</a>
You can then look for the referer value in the $GET array:
$page = (!empty($_GET['referer'])) ? $_GET['referer'] : 'unknown';
(Most advertisement referal programs work this way, giving each participating site specific values to be included in links to the seller's site.)