简体   繁体   English

试用期系统连同订阅 - PHP 和 MySQL

[英]The trial period system along with subscription - PHP and MySQL

I built a trial period system using PHP and Mysql and it is working completely fine.我使用 PHP 和 Mysql 构建了一个试用期系统,它运行良好。 But what I'm trying to achieve is that it should automatically update the time period, once the user buys the subscription.但我想要实现的是,一旦用户购买订阅,它应该自动更新时间段。 For example, if a user signs up for 30 days subscription, then it should increase by 30 days.例如,如果用户注册了 30 天的订阅,那么它应该增加 30 天。

I'm not expecting someone to write the code for me.我不希望有人为我编写代码。 Just want to know how it could be done.只是想知道它是如何做到的。 Because this is the first time I'm building such a thing.因为这是我第一次构建这样的东西。 Need your guidance on it!需要您的指导!

and I know code is vulnerable to SQL Injection.我知道代码容易受到 SQL 注入的影响。 You can ignore it because this is just for testing purpose您可以忽略它,因为这仅用于测试目的

<?php 

session_start();

include 'db-connection.php';

   $user_email = mysqli_real_escape_string($connection, $_POST['user_email']);
   $user_pass = mysqli_real_escape_string($connection, $_POST['user_pass']);
   
   $select_user = "select * from users where user_email='$user_email'";
   $select_user_query = mysqli_query($connection, $select_user);
   $user_email_count = mysqli_num_rows($select_user_query);

   if($user_email_count) {
       $user_result_array = mysqli_fetch_array($select_user_query);
       $user_db_pass = $user_result_array['user_pass'];
       $user_id = $user_result_array['user_id'];
       $user_name = $user_result_array['user_name'];
       
     
       
       if($user_pass === $user_db_pass ) {
           $_SESSION['user_id'] = $user_id;
           $_SESSION['user_name'] = $user_name;
           
       $user_registration_date = new DateTime($user_result_array['user_registration']); // This fetch the user registration date from database
       $today_date = new DateTime();
       $trial_period = 7;
       $date_diff = date_diff($user_registration_date,$today_date);
       $date_difference = $date_diff->format('%d days');
           
           if($date_difference >= $trial_period){
             echo "Trial period is over";
           } else {
             echo "<span class='alert alert-success'>Login Successful</span>";
           }
       
       } else {
           echo "<span class='alert alert-danger'>You have entered wrong password</span>";
       }
       
   } else {
       echo "<span class='alert alert-danger'>No Record Found</span>";
   }

?>

Once the trial period is over, it would redirect the user to the trial.php page where the user would be asked to do the payment.试用期结束后,它会将用户重定向到 trial.php 页面,要求用户付款。

Once the payment is made, it should increase the time period (this is the step which I don't know how to achieve)一旦付款,它应该增加时间段(这是我不知道如何实现的步骤)

User Table用户表

User_id | user_registration | user_name | user_email | user_pass | user_phone

  1. Add expiry_date column in user table (which will be added auto after registration.. like current_date + 30 days . Plus add one more column fees_paid=0 .在 user 表中添加expiry_date列(注册后将自动添加.. 比如current_date + 30 days 。另外添加一列fees_paid=0

  2. If you are using payment gateway for payment, then send auto email with payment link to user before trial period expires .如果您使用支付网关进行支付,请在试用期到期之前将带有支付链接的自动 email 发送给用户 If user make payment, update database expiry_date with registartion_date + 60 days (or XX Days, you want to add) and fees_paid=1 alogn with other payment details like payment date, payment_id etc... via webhook response along with payment details.如果用户付款,请使用 registartion_date registartion_date + 60 days (或您要添加的 XX 天)更新数据库expiry_date ,并通过 webhook 响应以及付款详细信息,将fees_paid=1与其他付款详细信息(如付款日期、payment_id 等)登录。

  3. If you are not using payment gateway and collecting payment via neft / cash etc., then via your admin panel, activate user's account by adding desired days in registration_date of user.如果您不使用支付网关并通过 neft / 现金等方式收款,则通过您的管理面板,通过在用户的adding desired days in registration_date激活用户的帐户。

In database, you can add some columns like fees_paid = 0 / fees_paid = 1 (0 for not paid and 1 for paid), order_number= random_generated_unique_string , payment_date , payment_id etc for saving payment details.在数据库中,您可以添加一些列,如fees_paid = 0 / fees_paid = 1 (0 表示未支付,1 表示已支付)、 order_number= random_generated_unique_stringpayment_datepayment_id等以保存付款详情。

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

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