Allowing File to Download Only for Subscribed Members Using PHP - Mostlikers

08 June, 2016

Allowing File to Download Only for Subscribed Members Using PHP

Recently i have implemented subscribe to download for facebook login download file. After that I got many request tutorials related with topic script. In this article i have explain about how to allowing file to download only for subscribed members using php and ajax. Follow and implement this logic to your website you will get more subscribe users. If your using google feed burner subscription you have to upload manually website subscriber email list to the database.  

Allowing File to Download Only for Subscribed Members Using PHP

For more about the newsletter subscription follow the below topic


Create a new 'users' table below structure insert your subscriber list.
  `email` varchar(100) NOT NULL,
  `status` enum('0','1') NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)

Download File Path

Create a download file in any file format (zip,rar,jpeg,png,pdf,txt) save it the project path location.
Ex :

Downloading the file script explanation.

  1. Register new subscriber email to the database.
  2. Verify the subscriber user email id for the verification process send email with the activation link.
  3. if user activate the email email change table column value 0  => 1.


Contains simple HTML code. <div id ="checking_result"> ajax error response display.
<div><h4>Download script  for Subscribed users only!</h4></div>
  <input type="text" name="email" id="email"/>
  <input type="submit" id="form_download" value="Download" ><br/>
<div id="checking_result"></div>

Jquery code

$('#form_download ').click - Input email value post to the ajax_download page. Here i have used json to post and get the response. 
<script src="//"></script>
<script type="text/javascript">
    var user_email = $('#email').val();
    $.post('ajax_download.php', {email_id : user_email},
    function(data) {
      if(data.status=='1') location.href=data.url; 
      else $('#checking_result').html(data.msg);
    }, "json");

Ajax code response (ajax_download.php)

Contains PHP code. This script helps you to check email id valid or not. $zipFile - Downlaod file location.  
$db = new mysqli('localhost', 'root', '', 'mostlikers'); 
//database connection
    $fetch=$db->query("SELECT * FROM `users` WHERE `email` = '$email'");
    //check the email 
    if($count==1) : 
    //status '0' - not verify. 
            $msg="Your email id not verified, subscribe again.";           
        else :
            $status = '1';
            $zipFile = "http://yourhost/download_demo/";
            //Path location
            $msg="Download file";            
    else : 
        $msg="Sorry no email found subscribe below.";
echo json_encode(array('url' => @$zipFile,'status' => @$status,'msg' => @$msg));

Related Topics


  1. Thanks Karthick, for the tutorial, but on question arises here in mind, that,
    you created users table to store subscribers email, but we have subscribers in feedburner so how we can fetch active subscribers from feedburner so that we can give them downloadable files... i am asking about it...

    1. Export your feedburner email list insert to database. Update new user list currently I am updating manually. Wait 2 days I will find feedburenr old api code, because Google has removed that API documentation.

    2. ok, thanks karthick you are the best blogger as well as programmer :)

  2. Hello,
    Iam developing the ecommerce website for a monthly magazine.once the user has subscribed for annual subscription, he has to be given access to download 12 files.Once he downloads the file the download button should be disable.

    Iam facing issue after downloading one magazine and if the page is refreshed, the download option is getting enabled again for that user.But i need once the downloading is completed the download option should be disable for the entire downloading of full magazines.After downloading of full magazines the button should be enable.For subscribed user.
    I need a solution with database.Please send me source code.

    1. Create a subscribe_new new table (id,userid,download_status enum(0,1),date)

      The moment user click the download button by using Ajax insert userid and status =1 subscribe table. In download page check whether that userid already exists or not. If tha user downloaded file, make you button disable.