View Full Version : Get sending page name

12-18-2010, 06:16 PM
I'm working with Paypal and after someone makes a payment on Paypal I'm redirecting them back to a receipt page that I'm hosting. I don't want this page to display anything unless the redirecting page is Paypal, is there anyway to control this with PHP?

Thanks in advance.

12-18-2010, 06:31 PM
dont recreate the horse, paypal handles this for you in your paypal script for the product sale, if you dont advertise your receipt page and nonone knows about it then the only way anyone can see it is from the paypal process using the return url in your code..

there are two return url for paypal, one is set inside your account as the default, and the other is set in specific in your code...

if you want every customer to go to the same place every time after every sale then put the url in your account, it will override anything else..

if you have dif places to send them depending on the product type then use the return url in the payment code process..

if you just want to keep anyone from typing the receipt page url in their browser window and bringing it up manually you can always control that with htaccess or you can put a switch in the page header that if the var are not set then send them to the main page....

12-18-2010, 06:37 PM
Thanks for the post, yeah I've already set it in my Paypal preferences. I guess I just don't have to let anyone know it's out there. Could you give me more specifics about the htaccess though? If I put it in there can I control htaccess to basically not show it if someone types in the adress but if someone got to it from a redirect then that's ok?

12-18-2010, 07:21 PM
if they do bring it up then its not gonna show anything just a blank page with no data right..

i know you can do some pretty fancy stuff with mod rewrite and im not an htaccess or mod rewrite pro by far so for that prob someone better can help you..

but what i would do, is one of two things or both..

first if they need to be logged in to purchase then the user session should be set for them already. and just going to paypal and back wont break that link.. so you could just say something like if !$SESSION or use isset with it to check to see if session is set, if not then use header location to send them to the main page of the site..

or if they are not required to be a member or be logged in you could just use the same methology on another var...
whatever you use for your payment var that you display on the receipt page you could just say if !isset that var name then send them to the home page using header location,

basically, if that val is not set it means they didnt come from paypal because there is no value, if it is set then you know they are finishing up a sale and you can let them in..

hope that helps you, if you really want to do the htaccess and some fancy stuff then i would suggest reposting a reply and maybe one of the pro's here can help do that...


12-18-2010, 08:31 PM
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:


Then in your receipt.php page, check if the referer_url is equal to 'paypal' and if not, then don't show the page.

if($_GET['referer_url'] != 'paypal') {
die('go away!');
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Thank You</title>
<h1>Thank You for your PayPal transaction!</h1>

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