admin管理员组文章数量:1429064
Can I create a page that is only viewable to people that have made a PayPal payment?
I am looking for users to make a payment before they can access a page, and if someone tried to view the page without a payment being made they would be redirected to an error page
Is this even a simple task?? If so, how would I go about setting this up and is there any tutorials online?
It's just a simple 2 page site I'm creating. Nothing plex....
I'm using the standard PayPal button just now but I'm not sure it's that simple
<form action="; method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="V6RE5BUJCBAPU">
<input type="image" src=".gif" border="0" name="submit" alt="PayPal — The safer, easier way to pay online.">
<img alt="" border="0" src=".gif" width="1" height="1">
</form>
Can I create a page that is only viewable to people that have made a PayPal payment?
I am looking for users to make a payment before they can access a page, and if someone tried to view the page without a payment being made they would be redirected to an error page
Is this even a simple task?? If so, how would I go about setting this up and is there any tutorials online?
It's just a simple 2 page site I'm creating. Nothing plex....
I'm using the standard PayPal button just now but I'm not sure it's that simple
<form action="https://www.paypal./cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="V6RE5BUJCBAPU">
<input type="image" src="https://www.paypalobjects./en_US/GB/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal — The safer, easier way to pay online.">
<img alt="" border="0" src="https://www.paypalobjects./en_GB/i/scr/pixel.gif" width="1" height="1">
</form>
Share
Improve this question
edited Jan 8, 2024 at 22:57
Codesmith
6,8315 gold badges45 silver badges64 bronze badges
asked Aug 8, 2011 at 10:07
GezzamondoGezzamondo
1,6294 gold badges15 silver badges26 bronze badges
2 Answers
Reset to default 3A possible solution is indeed to create a PayPal button. After the user has made the payment you can redirect him/her to a custom page which tells them they have successfully made the payment. You can let PayPal post the payment data to this page and you can verify this way that indeed the payment has been done successfully.
If so, you can set a SESSION or COOKIE variable and on your "target" page (the one they can only access after paying) you can verify if the SESSION or COOKIE has been set or not. If not, redirect them to the payment page.
Example
Make use of something like:
<form action="https://www.paypal./cgi-bin/webscr" method="post">
<input type="hidden" name="return" value="http://www.yourwebsite./index.php?payment=success" />
</form>
So after the payment has been done the user is redirected to index.php?payment=success and there you read the post from PayPal:
<?php
$req = "cmd=_notify-synch";
$tx_token = $_GET['tx'];
$auth_token = "<your auth token here>";
$req .= "&tx=$tx_token&at=$auth_token";
//Post back to Paypal system to validate:
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen('ssl://www.paypal.', 443, $errno, $errstr, 30);
if (!$fp) {
//HTTP ERROR
}
else {
fputs($fp, $header . $req);
//Read body data:
$res = '';
$headerdone = false;
while (!feof($fp)) {
$line = fgets($fp, 1024);
if (strcmp($line, "\r\n") == 0) {
$headerdone = true;
}
else{
$res .= $line;
}
}
//Parse the data:
$lines = explode("\n", $res);
$keyarray = array();
if (strcmp($lines[0], "SUCCESS") == 0) {
//Checks the payment_status is pleted
//check that txn_id has not been previously processed
for ($i = 0; $i < count($lines); $i++) {
list($key, $val) = explode("=", $lines[$i]);
$keyarray[urldecode($key)] = urldecode($val);
}
}
//Process payment:
$firstname = $keyarray['first_name'];
$lastname = $keyarray['last_name'];
//etc... you can either insert the payment data into your database for future reference
//Or set up a COOKIE for the user to be able to download your file.
//Or if your payment has been successful, redirect him to a "secret" page where the file is visible.
}
?>
There'll be many solutions to your problem and one could be as follows ..
You can create a Paypal IPN handler page which updates your database when a payment is made. Then you can manually process all the payments and allow those users to view the restricted content. [I am assuming that you have some sort of user management system and are able to allow/disallow users to view some content.]
Just fyi, When you create a paypal button, you can also provide success page URI and failed/canceled page URI.
I hope this helps.
本文标签: phpAccessing a page only after a paypal payment has been madeStack Overflow
版权声明:本文标题:php - Accessing a page only after a paypal payment has been made? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745503176a2661124.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论