Skip to content

Instantly share code, notes, and snippets.

View shohag-cse-knu's full-sized avatar

Syfur Rahaman Shohag shohag-cse-knu

View GitHub Profile
@shohag-cse-knu
shohag-cse-knu / sql_caching_sha2_password.sql
Created December 17, 2024 10:37
To resolve caching sha2 password in SQLYog
ALTER USER 'Syfur'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
@shohag-cse-knu
shohag-cse-knu / php_post_api_call_using_curl.php
Created December 17, 2024 09:20
POST API call using curl in PHP Codeigniter
<?php
$url = base_url().'index.php/controller_name/function_name';
$ch = curl_init($url);
$id = 1;
$code = 'DHA';
$myvars = 'id='.$id.'&code='.$code;
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $myvars);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt( $ch, CURLOPT_HEADER, 0);
@shohag-cse-knu
shohag-cse-knu / php_file_tempering_check.php
Created December 17, 2024 09:15
File is tempered or not in the server storage can be checked compared to the uploading time and file modification time
<?php
$Msg = "";
$row = $this->db->query("SELECT folder_name, file_name, uploaded_time FROM documents")->row();
$folder_name = $row->folder_name;
$filename = $row->file_name;
$uploaded_time = $row->uploaded_time;
$file_path = getcwd().DIRECTORY_SEPARATOR.$folder_name.'/'.$filename;
if (file_exists($file_path)) {
@shohag-cse-knu
shohag-cse-knu / php_get_datepicker_date_from_input.php
Created December 17, 2024 09:08
Get date from datepicker in PHP
<?php
echo implode('-', array_reverse(explode('/', $this->input->post('date'))));
/* Result:
2024-12-12
*/
?>
@shohag-cse-knu
shohag-cse-knu / php_newline_remove_from_string.php
Created December 17, 2024 09:00
Removing newline from db columns using PHP
<?php
echo htmlspecialchars_decode(str_replace(array("\r\n", "\r", "\n"), "<br />", $var));
?>
@shohag-cse-knu
shohag-cse-knu / php_ajax_request_check.php
Created December 17, 2024 08:58
AJAX request is being checked from PHP script
<?php
//only ajax request can connect this file
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest')
{
//CODE HERE
}
?>
@shohag-cse-knu
shohag-cse-knu / php_replace_all_characters_without_alphanumeric.php
Created December 17, 2024 08:55
Replacing all characters with empty character and keeping only alphanumeric characters
<?php
$var = "SRSabc__098";
echo preg_replace('/[^A-Za-z0-9]/', '', trim($var));
/*
Result:
SRSabc098
*/
?>
@shohag-cse-knu
shohag-cse-knu / php_subarray_merge_in_2D_array_according_to_key.php
Created December 17, 2024 08:47
Sub array merge in 2D array according to key using PHP
<?php
$source = array(
array("1" => 5),
array("2" => 1525),
array("2" => 12365),
array("2" => 34234),
array("3" => 324234)
);
$result = array();
@shohag-cse-knu
shohag-cse-knu / php_textarea_trimming_before_save.php
Created December 17, 2024 08:42
Textarea value trimming using PHP before save to database
<?php
echo htmlspecialchars(trim(preg_replace("/\r|\n|\r\n|\r\r/", " ", $input_var)));
?>
@shohag-cse-knu
shohag-cse-knu / php_convert_money_to_words.php
Created December 17, 2024 06:39
Converting the number of money in words
<?php
function convert_number_to_words($number) {
$hyphen = '-';
$conjunction = ' and ';
$separator = ', ';
$negative = 'negative ';
$decimal = ' point ';
$dictionary = array(
0 => 'zero',