简体   繁体   English

PHP页面保护

[英]PHP page protection

I am selling digital products on my site, and I want to set up some kind of page protection. 我正在网站上销售数字产品,并且我想设置某种页面保护。 My customers are paying through PayPal. 我的客户通过PayPal付款。 I have a link on the "submit" page to PayPal checkout, and have set up my checkout to redirect to the "information" page. 我在“提交”页面上具有指向PayPal结帐的链接,并且已将我的结帐设置为重定向到“信息”页面。 The information page is what I want to protect. 信息页面是我要保护的内容。

Here's the code I have so far, but for some reason it's not working, I keep getting the "else" statement... 这是我到目前为止的代码,但是由于某种原因它不起作用,我不断收到“ else”语句。

<div id="info">
<ul>
<li>
<?php 
if ( $_SERVER['HTTP_REFERER'] == "https://www.paypal.com/" ){

echo 'information...';

}else{
echo 'You need to pay first...';
}
?>
</li>
</ul>
</div>

Anybody see what I'm doing wrong? 有人看到我在做什么错吗? Or have a better option? 还是有更好的选择?

Thanks! 谢谢!

$_SERVER['HTTP_REFERER'] can easily be faked by anyone. $_SERVER['HTTP_REFERER']可以轻易被任何人伪造。 How important is your security? 您的安全性有多重要? If it's crucial that no one accesses the page without paying then do not rely on HTTP_REFERER. 如果至关重要的是没有人不付费就访问该页面,则不要依赖HTTP_REFERER。

I haven't used paypal for a long time, but when I did they had a callback url that you use to verify payments. 我已经很长时间没有使用Paypal了,但是当我这样做的时候,他们有一个回调网址用于验证付款。 The data flow should look like this 数据流应如下所示

  Your Server Paypal User submits payment form <-----------Paypal sends transaction information to your callback url You send the information back-----------------------------------> <---------Paypal sends back confirmation that they sent you that data (The data wasn't faked) 

Now you check what the transaction information says. 现在,您检查交易信息的内容。 If the user made a payment you store that record in a database of some sort so that you can verify they paid anytime in the future. 如果用户付款,则将该记录存储在某种数据库中,以便您可以验证他们将来是否已付款。

Update 更新资料

Here is a PHP code sample from Paypal to get you started: https://cms.paypal.com/cms_content/US/en_US/files/developer/IPN_PHP_41.txt 这是贝宝(Paypal)的PHP代码示例,可以帮助您入门: https : //cms.paypal.com/cms_content/US/en_US/files/developer/IPN_PHP_41.txt

That page becomes a callback/notification page. 该页面将成为回调/通知页面。 You don't put any of that code on the page you want to protect. 您无需在要保护的页面上放置任何代码。 Instead you store information in a database when the payment is verified on that page and then you check that the payment has been verified on the page you're protecting. 相反,当您在该页面上验证了付款后,便将信息存储在数据库中,然后检查所保护页面上的付款是否已验证。

Use PayPal's IPN to handle the callback. 使用PayPal的IPN处理回调。 That will confirm without question that the user purchased. 毫无疑问,这将确认用户已购买。 https://www.paypal.com/ipn https://www.paypal.com/ipn

<?
$ref=$_SERVER['HTTP_REFERER'];
if (strpos($ref,'https://paypal.com') !== false) {
    echo 'ok';
}else{
    echo 'error';
}
?>

as some have commented, relying on HTTP_REFERER is far from secure 正如一些评论所言,依靠HTTP_REFERER远非安全

however to get what you are trying to do working i would change your code to something like this 但是要获得您正在尝试执行的工作,我会将您的代码更改为如下所示

this will detect if the referrer contains "https://www.paypal.com/" rather then == to 这将检测引荐来源网址是否包含“ https://www.paypal.com/”,而不是==来

if (strpos($_SERVER['HTTP_REFERER'], "https://www.paypal.com/") !== FALSE)) {

When working with PayPal, there are number of ways to handle purchase of goods. 与贝宝(PayPal)合作时,有多种处理商品购买的方法。 I would suggest the option with callback. 我建议使用回调选项。 You specify specific url that will handle the paypal callback data. 您指定将处理Paypal回调数据的特定URL。 In that url, you do the data verification as described in PayPal development documentation. 在该URL中,您按照PayPal开发文档中的说明进行数据验证。 In that case, when customer is redirected back to your page, what you do is you lookup in db to see the status of the purchase. 在这种情况下,当客户被重定向回您的页面时,您要做的是在db中查找以查看购买状态。 If callback data has not been received yet, you wait, and recheck. 如果尚未收到回调数据,请等待,然后重新检查。 Once you have received callback from PayPal and you explicitly know if payment happened or no, then based on that you should either give access to your customer or no. 一旦您收到了来自PayPal的回叫,并且您明确知道是否进行了付款,则应基于此授​​予客户访问权或否。

Using Referrer is BAD, as many customers have been seen with this thing disabled. 使用Referrer是很糟糕的,因为已经看到很多禁用此功能的客户。 Also, this can be easily changed and your "protected" area would be more than easy to access. 而且,可以轻松更改此设置,并且您的“受保护”区域将比访问更容易。

Regards, J. 此致J.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM