Get referrer URL - visitors coming from Paypal (HTTPS)

删除回忆录丶 提交于 2019-11-27 06:02:51

问题


Hi I'm trying to get the referrer url but it doesn't work when the visitor comes to the site from Paypal

$ref = $_SERVER['HTTP_REFERER'];
echo $ref;

Is there a simple way to get the paypal url if the visitor land on the site coming from Paypal ?

Edit and Clarification: I'm not looking to have any special settings on the Paypal site (including but not limited to: IPN, set the return URL, Payment Data Transfer or any other special settings on the Paypal site) All that I'm looking is to get the URL referer when visitors come to the site from Paypal, regardles of the status of a transaction (if there was one).

As pointed by Bob from the manual

$_SERVER is an array containing information such as headers, paths, and script locations. The >entries in this array are created by the web server. There is no guarantee that every web >server will provide any of these; servers may omit some, or provide others not listed here.

So the only question left is - Is there any workaround to this without set something on the paypal site ?


回答1:


In case your site uses HTTP (not HTTPS) and PayPal uses HTTPS, there is no Referrer being sent!

HTTP RFC - 15.1.3 Encoding Sensitive Information in URI's states:

Clients SHOULD NOT include a Referer header field in a (non-secure) HTTP request if the referring page was transferred with a secure protocol.

So the only way to get the Referrer is to use HTTPS on your site.




回答2:


You can examine IPN. It sends notification when a transaction is affected.
URL : https://www.paypal.com/ipn




回答3:


The referer is unfortunatly set BY the client and some browser (or plugins) allow the user to edit what referer is sent to the server. It's never a good idea to trust "critical" (in your case I guess) informations sent by the user. However this is the only information you have regarding where the user comes from (if you decide not to use what paypal can offer).




回答4:


Quoted from PHP.net:

$_SERVER is an array containing information such as headers, paths, and script locations. The >entries in this array are created by the web server. There is no guarantee that every web >server will provide any of these; servers may omit some, or provide others not listed here.




回答5:


Thanks for your enlightment (in the comment). As Bob stated, you cannot rely on the information sent by the server. What I would do, is create a page an user has to go to before the payment, set a cookie (or session), redirect the user to the PayPal website. When the user returns to your website (either through PayPal, some links, or manually) you know the person hit the Pay button (as you set the cookie or session) and perform the actions you want to.

It's not what you asked, but might be an acceptable workaround.




回答6:


You can use document.referrer in javascript and send that to the server through ajax or something if you need




回答7:


Looking at this from a different persepective: If you are trying out find outwhere they came from before they went to PayPal, and you're site is sending them to PayPal (or you can get them to redirect via your website on the way to PayPal), set a cookie on your website before you redirect them, and then read the cookie when they return.

Sorry if again not what you need, but just checking you've considered it (as I also don't think you're going to win with the referrer).



来源:https://stackoverflow.com/questions/10430704/get-referrer-url-visitors-coming-from-paypal-https

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!