There are many ways to check using the various PayPal APIs, but alternatively as durangod suggested you can do a session check or simply check for a variable, like in your querystring.
Just to illustrate, here's an example of using the querystring.
So in your PayPal preference, have the return url set to your receipt page but append a variable to the url, like:
?referer_url=paypal
So your URL would look like:
Code:
http://www.mysite.com/receipt.php?referer_url=paypal
Then in your receipt.php page, check if the referer_url is equal to 'paypal' and if not, then don't show the page.
Code:
<?php
if($_GET['referer_url'] != 'paypal') {
die('go away!');
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Thank You</title>
</head>
<body>
<h1>Thank You for your PayPal transaction!</h1>
</body>
</html>
If the referer_url doesn't equal to paypal, the die command will stop the page from showing (and just display a message, "go away"). This will happen if someone goes to your page with just
http://www.mysite.com/receipt.php instead of
http://www.mysite.com/receipt.php?referer_url=paypal
Anyway, just one way of doing it.
EDIT: fixed a typo in the php code