PayPal provides many ways to redirect visitors to a designed page (return URL) after the payment. Moreover we would also like to pass some variables with the PayPal buy button back to the return URL to process. This way we can automated our payment process.

Today I am going to start with the most easiest method by using PayPal buy button.

1. Go to PayPal account and create a PayPal buy button as usual.

2. The default PayPal button will not redirect visitors to a page after the payment. We need to add the following lines to the button:

<input type=”hidden” name=”rm” value=”2″>
<input type=”hidden” name=”return” value=”http://www.returnURL.php?name=alex&amount=9.95″>

The above two lines will redirect visitors to the return URL with the passing variable as a string in the browser URL.

To demonstrate the payment process, two variabless (name and amount) also pass with the returnURL

3. Prepare a webpage to test the PayPal buy button. The HTML code of the button is:

<form name="_xclick" action="" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="item_name" value="test buy">
<input type="hidden" name="amount" value="0.12">
<input type="hidden" name="rm" value="2">
<input type="hidden" name="return" value="http://www.returnURL.php?name=alex&amount=9.95">
<input type="image" src="" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">

Here’s how the webpage look like.

4.  In order to demonstrate processing the passing variables in the return URL, I also prepared the following simple PHP codes:


$name = $_GET[“name”];
$amount = $_GET[“amount”];

if ((!$name)) {
echo “The name parameter is empty!”;

echo “Name is: ” . $name . “<br />”;
echo “Amount is: ” . $amount;


5.  Upload the returned URL file to my hosting server.

6. Everything is ready. Let’s try to process the payment by clicking on the PayPal button.

7. The PayPal payment screen appear. Log in the PayPal account to settle the payment.

8. Click on the Pay Now button to settle the payment.

9. The payment finished and redirect to the designed return URL after 10 seconds.

10. The screen of the return URL page print out the name and amount of the two passing variables, as shown below:

This is the most easiest method for PayPal buy button with return URL and passing variables.