Posts

Showing posts with the label PHP

HTTPS Setup With Certbot in Digital Ocean Droplets

For Installation sudo apt install python3-certbot-apache For Activation sudo certbot --apache --expand -d domainname.com

Plain php text showing issue solve

Solution: 1 sudo systemctl status php8.1-fpm sudo apt-get install php8.1-fpm sudo apt install apache2 libapache2-mod-fcgid sudo apt install libapache2-mod-fcgid sudo a2enmod actions fcgid alias proxy_fcgi Solution: 2 sudo a2dismod mpm_event sudo systemctl restart apache2 sudo a2enmod mpm_prefork sudo systemctl restart apache2 sudo a2enmod php7.0 sudo systemctl restart apache2

Fixed: Requested URL Was Not Found on this Server Apache2 Ubuntu

When you install Apache2 on a Linux server. At that time mod_Rewrite module is not enabled by default on apache 2. And of which website or app you run on the server, and you open any url of this, then you see the message “the requested url was not found on this server apache2 ubuntu”. So in the tutorial “the requested url was not found on this server apache2 ubuntu” you will learn how to enable rewrite_module and solve this error. The apache Mod_rewrite is very popular for rewriting human-readable URLs in dynamic websites. This makes the URL’s look cleaner and SEO-friendly on websites. In this tutorial, we will show you how to enable the apache/2.4.5 ubuntu mod_rewrite module and configure it for use .htaccess files available with apache 2 ubuntu web server at port 443, 80. Step 1 – Update dependencies sudo apt-get update If you want to enable mod_rewrite apache in ubuntu. So, you can connect your instance or web server to ssh terminal. And then type a2enmod command to enable any modul...

CURL

*** Initialize a cURL session $ch = curl_init(); *** Set the URL that you want to GET by using the CURLOPT_URL option. curl_setopt($ch, CURLOPT_URL, $url); *** Set CURLOPT_RETURNTRANSFER so that the content is returned as a variable. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); *** Set CURLOPT_FOLLOWLOCATION to true to follow redirects. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); *** Timeout after 120 seconds curl_setopt($ch, CURLOPT_CONNECTTIMEOUT , 120); *** Start counting time for response from BL API. $time_start     = microtime(true); $requestTime    = Carbon::now()->format('Y-m-d H:i:s'); *** Execute the request. $response   = curl_exec($ch); *** End counting, and calculate time for response from BL API. $time_end       = microtime(true); $responseTime   = Carbon::now()->format('Y-m-d H:i:s'); $execution_time = ($time_end - $time_start)*1000; *** Return a string containing the ...

Upload file with uploading progress

index.php <script type="text/javascript">     function _(el){         return document.getElementById(el);     }     function uploadFile(){         var file = _("file1").files[0];         var formdata = new FormData();         formdata.append("file1",file);         var ajax = new XMLHttpRequest();         ajax.upload.addEventListener("progress",progressHandler,false);         ajax.addEventListener("load",completeHandler,false);         ajax.addEventListener("error",errorHandler,false);         ajax.addEventListener("abort",abortHandler,false);         ajax.open("POST","server_page.php");         ajax.send(formdata);     }     function progressHandlere(vent){         _("load...

Tracking Number Generation Process

$trackingPrefix = "PI" . date("dmY"); $processTypeId = 1; $updatePurchaseTrackingNo = DB::statement("update  ins_purchase_invoice, ins_purchase_invoice as table2 SET ins_purchase_invoice.tracking_no=(    select concat('$trackingPrefix',     LPAD( IFNULL(MAX(SUBSTR(table2.tracking_no,-4,4) )+1,0),4,'0')                   ) as tracking_no    from (select * from ins_purchase_invoice ) as table2    where table2.id !=  $purchaseData->id and table2.tracking_no like '$trackingPrefix%'    ) where ins_purchase_invoice.id = $purchaseData->id and table2.id = $purchaseData->id");

AJAX IMAGE UPLOADING.....

1. index.php <body>     <span id="msg" style="color:red"></span><br/>     <input type="file" id="photo"><br/>   <script type="text/javascript" src="jquery-3.2.1.min.js"></script>   <script type="text/javascript">     $(document).ready(function(){       $(document).on('change','#photo',function(){         var property = document.getElementById('photo').files[0];         var image_name = property.name;         var image_extension = image_name.split('.').pop().toLowerCase();         if(jQuery.inArray(image_extension,['gif','jpg','jpeg','']) == -1){           alert("Invalid image file");         }         var form_data = new FormData();         form_data.append("file",property);       ...

Virtual Host setup in XAMPP

1. xampp\apache\conf\extra\httpd-vhosts.conf <VirtualHost *:80>     ServerAdmin hasib.dev     DocumentRoot "C:/xampp/htdocs/hasib/"     ServerName hasib.dev </VirtualHost> 2.Windows\System32\drivers\etc\hosts 127.0.0.1 hasib.dev

Loop

$x=1; do{  echo $x;  $x++; }while($x<=10); //At first code will be executed in do{} and then will be continuing checking condition if condition true then will go inside in do{} to execute code otherwise not. An important thing about do{}while() is At the very first execution is not depend on condition but from the second execution depend on condition. $x=1; while($x<=10){  echo $x;  $x++; } //At the beginning check the condition if condition is true then execute otherwise not. The characteristic of this loop is this loop run clock wise. for($i=1; $i<=10; $i++){  echo $i; } // This loop run anti-clock wise first initiate value, then check condition if condition is true then go to execution, after completing the execution go to the third parameter to increment initialized value. continue; //Use to skip a single execution in loop break; //Use to get out from a loop;

Getting key from an array by value

if(in_array($data['question_type],$questionTypes)){    $examTypeId = array_search($data['question_type'],$questionTypes); }

Project run on port [PHP]

Generally :  php -S localhost:8000 Laravel :  php artisan serve  [Port number will be atomically 8000] php artisan serve --port=8888 [Run on custom port]  php artisan serve --host=192.168.152.160 --port=8800  [Run on custom IP and custom port] 

PHP BUILT-IN FUNCTIONS

strtolower() - converts a string to lowercase. lcfirst() - converts the first character of a string to lowercase. ucfirst() - converts the first character of a string to uppercase. ucwords() - converts the first character of each word in a string to uppercase.

APACHE SERVER (START || STOP || RESTART)

START> sudo service apache2 start STOP> sudo service apache2 stop RESTART> sudo service apache2 restart

TO SEE PHP VERSION ON UBUNTU

1st step : sudo update-alternatives --install "/usr/bin/php" "php" "/opt/lampp/bin/php" 1 2nd step : Enter User Password 3rd step : php -v

DATA VIEW FROM MYSQL DATABASE THROUGH PDO PROCESS

//LOGICAL TEMPLATE (CLASS || student.php) class Student{ protected $db_connect; public function __construct(){ $host_name = 'localhost'; $user_name = 'root'; $password = ''; $db_name = 'db_test'; try{ $this->db_connect = new PDO("mysql:host={$host_name}; dbname={$db_name}",$user_name,$password); }catch(PDOException $e){ echo $e->getMessage(); } } public function select_all_student_info(){ try{ $student_info = $this->db_connect->prepare("SELECT * FROM tbl_student"); $student_info->execute(); return $student_info; }catch(PDOException $e){ echo $e->getMessage(); } } } //VIEW PAGE <?php require_once('student.php'); $obj_student = new Student(); $student_info = $obj_student->select_all_student_info(); ?>   <fieldset>   <legend>View Student Form</legend>   <table border="1" cellpad...

DATA INSERT INTO MYSQL DATABASE THROUGH PDO PROCESS

<?php class Student{ protected $db_connect; public function __construct(){ $host_name = 'localhost'; $user_name = 'root'; $password = ''; $db_name = 'db_test'; try{ $this->db_connect = new PDO("mysql:host={$host_name}; dbname={$db_name}",$user_name,$password); }catch(PDOException $e){ echo $e->getMessage(); } } public function save_student_info($data){ $student_info = $this->db_connect->prepare("INSERT INTO tbl_student(student_name,phone_number,email_address) VALUES(:a,:b,:c)"); $student_info->bindParam(':a',$data['student_name']); $student_info->bindParam(':b',$data['phone_number']); $student_info->bindParam(':c',$data['email_address']); $student_info->execute(); } }

Best Example of Inheritance

<?php class DB_Connection{ private $host = 'localhost'; private $user = 'root'; private $pass = ''; private $db_name = 'test'; protected $db_connect; public function __construct(){ $this->db_connect = mysqli_connect($this->host,$this->user,$this->pass,$this->db_name); if(!$this->db_connect){ die('Connection Problem : '.mysqli_error($this->db_connect)); } } } class Student extends DB_Connection{ public function __construct(){ parent::__construct(); } } ?>

Ternary Operator PHP

() ? : ; (Condition) ? TRUE : FALSE ;

class two extends one {}

In object oriented php programming concept if I extends class one into class two and make an object named as $second = new two(); then what will happen actually ?? Then I can access all property of class one by using the object "$second->first_string;" cause I've extended all property of class one from class two. Note : One protected and public property is possible to access from other class.

What is callback function ?

A callback function also known as a higher-order function is, a function that is passed to another function as a parameter, and the callback function is called inside the other function.