Check referer and give a message

Hi all!

I have been trying to find how to get the refering url to a page of my website, check if it’s included on a txt file and then print a modal popup with a message. So, if you come from a friend url included on the txt it will welcomes you “You come from a friend’s url” for example, and if not, then another msg will be printed.

Someone knows? I have found codes for the different functions separately but don’t know how to put them all together to do this.

Thanks!

Start by showing us what you have tried thus far AND what errors, if any, you are getting.

Yes sorry, this is what I’ve tried and it reported me a 500 eror

<?php
if (ref.match(/^https?:\/\/([^\/]+\.)?friendsite\.com(\/|$)/i)) {
alert(“You came from a friend Website”);
else { alert(“You came from a non friendly Webstie”);
}
?>

Also, this code will just check if the referal matches just 1 specific address, bout I’d like to check more than just one. maybe getting them from a txt file?

What you’ve posted is JavaScript, not PHP code…

yep! sorry, but it doesn’t work anyway. does someone know any alternative for what I want to do? no matter php or java.
thanks!