Home arrow PHP arrow Page 2 - Database Tables for a PayPal IPN PHP Website Payments Application

Insert test products in productstable - PHP

This is the third part of the PayPal IPN PHP Script tutorial. This part will discuss the database table required by the application as well as the details of uploading and securing the digital products on the test server.

TABLE OF CONTENTS:
  1. Database Tables for a PayPal IPN PHP Website Payments Application
  2. Insert test products in productstable
By: Codex-M
Rating: starstarstarstarstar / 6
January 18, 2011

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Now that the products table has been created, you will need to insert test products into it. In this tutorial series, I'm using two sample ebooks. These products are  the ones that appear on the shopping page created in the second part of this tutorial: http://www.devshed.com/c/a/PHP/Creating-a-Paypal-IPN-System-in-PHP-Part-Two/

It is important that the product name and the product price exactly match what you are using in your PayPal buttons created in the second part of this tutorial. Below are the products that need to be inserted:

First test product

ProductName: Codex Ebook
ProductPrice: $30
Filename: codexebook.pdf

Second test product

ProductName: How to behave like a child
ProductPrice: $15
Filename: howtobehavelikeachild.pdf

Below is the MySQL insert command for the first product (you can also use phpMyAdmin to insert these products):

mysql> INSERT INTO productstable (ProductName,ProductPrice,Filename) VALUES ('Codex Ebook','30','codexebook.pdf');

And for the second product:

mysql> INSERT INTO productstable (ProductName,ProductPrice,Filename) VALUES ('How to behave like a child','15','howtobehavelikeachild.pdf');

This is what the products look like after being inserted:

http://www.php-developer.org/screenshot/productstablesample.jpg  

Upload Your Products into Your Test Server

Now that all of the database tables have been created, you are ready to upload your digital products (ebooks for example) to your hosting server. Follow the detailed steps below.

1. Suppose you will place your digital products inside a folder named "ebookdownloads." Also, suppose we will place the "ebookdownloads" folder inside the "paypal_ipn_demo" folder, which was created in the second part of this tutorial series. We will be doing this for testing purposes.

You will need to create the foldername "ebookdownloads" inside the "paypal_ipn_demo" folder using an SSH client, and then assign a folder permission of 755.

2. Now that the folder has been created, upload the two test products, codexebook.pdf and howtobehavelikeachild.pdf, to the "ebookdownloads" folder.

You can download the sample ebook used in this tutorial (unzip and extract the ebooks first): http://www.php-developer.org/wp-content/uploads/tutorials/sample_ebook.zip

The recommended file permission for the ebook is 644.

3. You also need to protect the ebook from direct downloading (using a browser and any other methods). You will be using the .htaccess method to deny public access to these ebooks.

If you are not going to protect this, then malicious users might be able to figure out the URL path of your ebook and download it without paying in PayPal.

To create an .htaccess file:

First, open a text editor (notepad or gedit in Linux), and add the following lines:

order deny,allow
deny from all

Save this file as .htaccess (do not forget to include a dot before the filename), and then upload the .htaccess file inside the ebookdownloads folder.

This is what it looks like inside an SSH client (Filezilla):

4. Try to directly download the ebook using a browser. For example, this is the actual path to download the codex ebook: http://www.php-developer.org/paypal_ipn_demo/ebookdownloads/codexebook.pdf

Downloading should be denied, and you should see the 403 forbidden error shown in the browser.

5. Reconfirm the server header status using a checker: http://gsitecrawler.com/tools/Server-Status.aspx

The result should be a 403 forbidden status:

Results of the GSiteCrawler Server-Test
Tested at 1/12/2011 6:20:47 AM / from 83.139.191.255:

URL=http://www.php-developer.org/paypal_ipn_demo/ebookdownloads/codexebook.pdf
Result code: 403 (Forbidden / Forbidden)

Now that direct downloading permission is denied, how would the user be able to download the ebook? The secure strategy is to let PHP read the file from the ebookdownloads folder (using the readfile PHP function) and let it force downloading the purchased ebook to the user.

Using this method, no one will be able to download the ebook, except for authenticated and valid customers in your website. The details of this PHP script and other IPN related scripts will be discussed in upcoming PayPal IPN PHP script tutorials.



 
 
>>> More PHP Articles          >>> More By Codex-M
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: