[go: up one dir, main page]

Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

JehanKandy/Train-Ticket-Booking-System-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

New Project Started

Train Ticket Booking System

Train Ticket Reservation System

GitHub Language Count GitHub Top Language GitHub Closed Pull Requests GitHub Last Commit GitHub Commit Activity (Week) Github License

Explain Functions

25 December 2022

reg_user()

function file

in first codeline

      function reg_user($username, $email, $pass, $cpass){
      $con = Connection();

      $chech_user = "SELECT * FROM user_tbl WHERE username = '$username' && email_user = '$email'";
      $chech_user_result = mysqli_query($con, $chech_user);
      $chech_user_nor = mysqli_num_rows($chech_user_result);

I used function for get user input username, email, passweord and Confirm Password from reg.php

      if(isset($_POST['register'])){
          $result = reg_user($_POST['username'], $_POST['email'],md5($_POST['pass']), md5($_POST['cpass']));
          echo $result;
      }

in first code i create php variable called $check_user and assign data which from user_tbl where username equal to $username and email equal to email and then I create a variable called $chech_user_result and assign mysqli_query($con, $chech_user);
mysqli_query function performs a query against a database.

more about mysqli_query

and the i again create variable called $chech_user_nor and assign mysqli_num_rows($chech_user_result); inoder to that the meaning of mysqli_num_rows() function for count data according to $chech_user_result = mysqli_query($con, $chech_user);

more about mysqli_num_rows

     if(empty($username)){
        return  "<div class='alert alert-danger alert-dismissible fade show' role='alert'>
                <strong>Username Error</strong> Username Cannot be Empty....!
                <button type='button' class='close' data-dismiss='alert' aria-label='Close'>
                <span aria-hidden='true'>&times;</span>
                </button>
        </div>";
    } 

in above code i check the $username is not empty, if the variable empty it gives output as 'Username Cannot be Empty....!' it's same for other 3 variable ($email, $pass, $cpass)

     if($pass != $cpass){
        return  "<div class='alert alert-danger alert-dismissible fade show' role='alert'>
                <strong>Password Error</strong> Password and Confirm Password not match..!
                <button type='button' class='close' data-dismiss='alert' aria-label='Close'>
                <span aria-hidden='true'>&times;</span>
                </button>
        </div>"; 
    }

in above code I check pass and $cpass it means password and Confirm Password is equal or not, if not equal it gives output as Password and Confirm Password not match..!

         if($chech_user_nor > 0){
            return  "<div class='alert alert-danger alert-dismissible fade show' role='alert'>
                <strong>User Error</strong> User Already Exists...!
                <button type='button' class='close' data-dismiss='alert' aria-label='Close'>
                <span aria-hidden='true'>&times;</span>
                </button>
        </div>"; 
        }

in above code I check that are there any users according to user enterd values, if there is existing user it gives output as User Already Exists...!
if there are not any user according to user added values the values insert to the database table called user_tbl as following

              $insert_user = "INSERT INTO user_tbl(username,email_user,user_pass,user_type,is_active,join_date)VALUES('$username','$email','$pass','user',0,NOW())";
            $insert_user_result = mysqli_query($con, $insert_user);

more about IF statements


26 December 2022

login_user()

in this function first codlines are same as reg_user() function.

 function login_user($username, $user_pass){
    $con = Connection();

    $check_user = "SELECT * FROM user_tbl WHERE username = '$username' && user_pass = '$user_pass' && is_active = 1 && is_pending = 0";
    $check_user_result = mysqli_query($con, $check_user);
    $check_user_nor = mysqli_num_rows($check_user_result);
    $check_user_row = mysqli_fetch_assoc($check_user_result);

but in last codeline i create a variable called $check_user_row and assign mysqli_fetch_assoc($check_user_result); the meaning of 'mysqli_fetch_assoc()' The fetch_assoc() / mysqli_fetch_assoc() function fetches a result row as an associative array.

more about mysqli_fetch_assoc

and then i check the username and password is empty or not usoing following codelines

    if(empty($username)){
        return  "<div class='alert alert-danger alert-dismissible fade show' role='alert'>
                <strong>Username Error</strong> Username Cannot be Empty....!
                <button type='button' class='close' data-dismiss='alert' aria-label='Close'>
                <span aria-hidden='true'>&times;</span>
                </button>
        </div>";
    }
    if(empty($user_pass)){
        return  "<div class='alert alert-danger alert-dismissible fade show' role='alert'>
                <strong>Password Error</strong>  Password Cannot be Empty....!
                <button type='button' class='close' data-dismiss='alert' aria-label='Close'>
                <span aria-hidden='true'>&times;</span>
                </button>
        </div>"; 
    }

now I check the user is panding user or not for that I use following codelines

    $waiting_user = "SELECT * FROM user_tbl WHERE username = '$username' && user_pass = '$user_pass' && is_active = 0 && is_pending = 1";
    $waiting_user_result = mysqli_query($con, $waiting_user);
    $waiting_user_nor = mysqli_num_rows($waiting_user_result);

    $_SESSION['waitingUser'] = $waiting_user_row['username'];
    
    if($waiting_user_nor > 0){
        header("location:waiting_user.php");
    }

in above code I create a session called $_SESSION['waitingUser'] for get login user's email to check the user is pending user or not if the user is pending user and header to waiting_user.php file

and I check are there any user according to user input values using

    if($check_user_nor > 0){

then I check the user is user or an admin for that i use following codelines

             if($check_user_row['user_type'] == 'user'){
                setcookie('login',$check_user_row['email_user'],time()+60*60,'/');
                $_SESSION['LoginSession'] = $check_user_row['email_user'];
                header("location:../routes/user.php");
            }
            elseif($check_user_row['user_type'] == 'admin'){
                setcookie('login',$check_user_row['email_user'],time()+60*60,'/');
                $_SESSION['LoginSession'] = $check_user_row['email_user'];
                header("location:../routes/user.php");
            }

in here i use setcookie and $_SESSION the meaning of setcookie is create a cookie for login user and it will expire after 1 hour (by time()+60*60,'/')

more about cookies

more about session

and lastly in this function i use following codelines

     else{
        if($check_user_row['is_active'] == 0){
            return  "<div class='alert alert-danger alert-dismissible fade show' role='alert'>
                    <strong>User Error</strong>  User Deactivate....!
                    <button type='button' class='close' data-dismiss='alert' aria-label='Close'>
                    <span aria-hidden='true'>&times;</span>
                    </button>
            </div>";  
        }else{
            return  "<div class='alert alert-danger alert-dismissible fade show' role='alert'>
                    <strong>User Error</strong>  User Does not Exists....!
                    <button type='button' class='close' data-dismiss='alert' aria-label='Close'>
                    <span aria-hidden='true'>&times;</span>
                    </button>
            </div>";  
        }
    } 

for if the user is deactivated buy admin the user can get output as User Deactivate if there are no existing user in database user can get outupt as User Does not Exists....!


waiting_user()

in order to this function I want to print user who is not active user and that user must be a pending user, for that i use following codeline to do that

function waiting_user(){
    $con = Connection();

    $waiting_user_username = strval($_SESSION['waitingUser']);

    echo $waiting_user_username;
}

in here I catch the value of following session using waiting_user_username = strval($_SESSION['waitingUser']);

    $_SESSION['waitingUser'] = $waiting_user_row['username'];

so that I use strval() for do that

more about strval


30 December 2022

check_otp_user($username, $email)

in this function i used for password reset (forget Password) function. and first code lines I mention 2 retun values in this fucntion as username and email, so that i catch the username and password that user enter in the form

   function check_otp_user($username, $email){
    $con = Connection();

and other functionalities are same as other functionalities as i mention above

and this fuction I mention as following

            $otp_num = rand(10000,99999);

            $receiver = $email;
            $subject = "Resent Password..!";
            $body = "OTP For Resent Password /n GYM Workout /n/n OTP is ".$otp_num;
            $sender = "From:jehankandy@gmail.com";

            if(mail($receiver,$subject,$body,$sender)){

in here i use inbuild function in php called mail()

becasue, I want to send password reset OTP to user registaion email address.

if this function not working in your project, becase there are some configaration in xampp server and the configarations are in following link,

XAMPP configuration Part 1

and

XAMPP configuration Part 2

in above function i create variable called otp_num and assign rand(10000,99999) value to this variable. inoder to this variable value, I want to get on of number between 10000 and 99999 as OTP so that i use inbuild function called rand() for get random number between 10000 and 99999

and then I hash that random number for store in database


check_otp($otp_no)
in this function i check the user entered OTP number with database stored OTP number. For that I hash user enterd OTP because when user request an OTP it will autometicaly hash and store in database. 

and the I chack user entered OTP and the currect OTP
for that I use following codeline to do that

    if($check_opt_nor == 0){
        return  "<div class='alert alert-danger alert-dismissible fade show' role='alert'>
                    <strong>OTP Error</strong>  Check Your OTP...!
                    <button type='button' class='close' data-dismiss='alert' aria-label='Close'>
                    <span aria-hidden='true'>&times;</span>
                    </button>
                </div>";  
    }else{
        if($otp_no != $check_otp_row['otp_no']){
            return  "<div class='alert alert-danger alert-dismissible fade show' role='alert'>
                        <strong>OTP Error</strong>  Invalid OTP Number..!
                        <button type='button' class='close' data-dismiss='alert' aria-label='Close'>
                        <span aria-hidden='true'>&times;</span>
                        </button>
                    </div>";  
        }
        else{
            header("location:update_pass.php");
        }
    }

if the both OTP numbers are currect the user rederect to the update_pass.php for update the user's password

more about md5()


31 December 2022

update_password($username,$email,$npass,$cnpass)

in this fucntion i used for update new password. so that I pass 4 variable for get user input values $username, $email, $npass and $cnpass for username, email, new password and Confirm Password according to this function in first code line identyfy the functuin

function update_password($username,$email,$npass,$cnpass){
    $con = Connection();

and the I cheack username, email, new password and Confirm Password are empty

    if(empty($username)){
        return  "<div class='alert alert-danger alert-dismissible fade show' role='alert'>
                <strong>Username Error : </strong> &nbsp; Username can not be empty...!
                <button type='button' class='close' data-dismiss='alert' aria-label='Close'>
                <span aria-hidden='true'>&times;</span>
                </button>
            </div>"; 
    }
    if(empty($email)){
        return  "<div class='alert alert-danger alert-dismissible fade show' role='alert'>
                <strong>Email Error : </strong> &nbsp; Email Can not be empty...!
                <button type='button' class='close' data-dismiss='alert' aria-label='Close'>
                <span aria-hidden='true'>&times;</span>
                </button>
            </div>"; 
    }
    if(empty($npass)){
        return  "<div class='alert alert-danger alert-dismissible fade show' role='alert'>
                <strong>Password Error : </strong> &nbsp; Password Can not be empty...!
                <button type='button' class='close' data-dismiss='alert' aria-label='Close'>
                <span aria-hidden='true'>&times;</span>
                </button>
            </div>"; 
    }
    if(empty($cnpass)){
        return  "<div class='alert alert-danger alert-dismissible fade show' role='alert'>
                <strong>Password Error : </strong> &nbsp; Confirm Password can not be empty...!
                <button type='button' class='close' data-dismiss='alert' aria-label='Close'>
                <span aria-hidden='true'>&times;</span>
                </button>
            </div>"; 
    }

and the i check password and confirm password are same

    if($npass != $cnpass){
        return  "<div class='alert alert-danger alert-dismissible fade show' role='alert'>
                <strong>Password Error : </strong> &nbsp; Passwords are not match...!
                <button type='button' class='close' data-dismiss='alert' aria-label='Close'>
                <span aria-hidden='true'>&times;</span>
                </button>
            </div>"; 
    }

then i check are there any user in database according to user enterd value. if there is a user according to the values,

        $check_user = "SELECT * FROM user_tbl WHERE username = '$username' && email_user = '$email'";

it will autometicaly update the database according to new password

        $update_pass = "UPDATE user_tbl SET user_pass = '$npass' WHERE username = '$username' && email_user = '$email'";
        $update_pass_result = mysqli_query($con, $update_pass);

and then i already create a session and cookie for update password now i uset cookie and destroy session

            setcookie('ResetPass',NULL,time()-60*60,'/');
            session_unset();
            session_destroy();
            header('location:login.php');

after that rederect to login.php


31 December 2022

update_password($username,$email,$npass,$cnpass)

Taday i update the function, in oderto that whem user get OTP and update the password, the data in password reset table must be delete, if not others can reset user password

            $delete_otp = "DELETE FROM pass_reset_tbl WHERE username = '$username' && email = '$email'";
            $delete_otp_result = mysqli_query($con, $delete_otp);

Development Timelne

18 December 2022

  1. DEVELOP
  • Project Start

19 December 2022

  1. DEVELOP
  • lib/layouts/header.php
  • index.php
  • lib/layouts/main_footer.php
  • css/style.css

21 December 2022

  1. DEVELOP
  • docs/find_train.php
  • lib/layouts/nav_bar.php
  1. UPDATE
  • index.php
  • css/style.css

22 December 2022

  1. DEVELOP
  2. UPDATE
  • css/style.css
  • docs/find_train.php

23 December 2022

  1. DEVELOP
  • docs/gallery.php
  • docs/about.php
  • docs/train_routes.php
  1. UPDATE
  • lib/layouts/main_footer.php
  • css/style.css
  • lib/layouts/nav_bar.php

25 December 2022

  1. DEVELOP
  • docs/news.php
  • lib/layouts/login_footer.php
  • lib/views/login.php
  • lib/views/reg.php
  • lib/function/config.php
  • lib/function/function.php
    • functions: reg_user()
  1. UPDATE
  • css/style.css
  • lib/layouts/nav_bar.php
  • index.php

26 December 2022

  1. DEVELOP
  • lib/views/waiting_user.php
  1. UPDATE
  • css/style.css
  • lib/layouts/login.php
  • lib/function/function.php
    • functions login_user()

27 December 2022

  1. DEVELOP
  • lib/views/fpass_check.php
  1. UPDATE
  • lib/views/login.php
  • css/style.css

28 December 2022

  1. DEVELOP

  2. UPDATE

  • lib/views/fpass_check.php
  • lib/function/function.php
    • functions check_otp_user()

30 December 2022

  1. DEVELOP
  • lib/views/check_otp.php
  • lib/views/update_pass.php
  1. UPDATE
  • lib/views/fpass_check.php
  • lib/function/function.php
    • functions check_otp($otp_no)

31 December 2022

  1. DEVELOP

  2. UPDATE

  • lib/views/update_pass.php
  • lib/function/function.php
    • functions update_password($username,$email,$npass,$cnpass)

01 January 2023

  1. DEVELOP
  • lib/layouts/nav_loged.php
  • lib/routes/admin.php
  • css/dashboard.css
  • js/script.js
  1. UPDATE
  • lib/layouts/header.php
  • lib/function/function.php
    • update functions - update_password($username,$email,$npass,$cnpass)

Developers

JehanKandy

Copyright and license

Copyright 2021–2022 JehanKandy. Train Ticket Booking System released under the MIT License