Skip to main content

Posts

Showing posts with the label PHP

How to Enable IMAP PHP in xampp

The imap extension comes as standard with the PHP installation. You just need to enable it in your php.ini   Enable IMAP in XAMPP: You need to configure your php.ini file to enable IMAP extension Search for the line ;extension=php_imap.dll and remove semicolon(;) and restart your xampp. The line should look like as mentioned below. extension=php_imap.dll Note : New php version does not have dll anymore. The default php.ini should already contain a line to load the extension but commented out: ;extension=imap Remove semicolon from above like below extension=imap Enable IMAP in Linux: If you are using LAMP server, First install IMAP using the command on terminal $ sudo apt-get install php5-imap To enable IMAP, run the following command. sudo phpenmod imap Restart apache server with below command sudo service apache2 restart

Simple PHP function to update data in Mysql Database

The below simple php function is used to update data into MySql database with out manually filling the update mysql query with input filed names. Function: function update_Defined($table, $data, $condition){     // update('table', array_map('trim',$_POST),'id='.$_POST['p_id']);     global $db;     $query = "UPDATE `" . $table . "` SET ";     $fis = array(); $vas = array();        foreach ($data as $field => $val){         $fis[] = "`$field`";         $vas[] = "'" . mysqli_real_escape_string($db,$val) . "'";     }        foreach ($fis as $key => $field_name) {         $fields[$key] = $field_name;         if (isset($vas[$key])) {             $fields[$key] .= '=' . $vas[$key];         }     }        $query .= implode(',', $fields);     $query .= " WHERE " . $condition;     //echo $query;exit;     Query($query); } Form: <form action="" method=

Simple Function to Insert data into MySql database using PHP

The below simple php function is used to insert data into MySql database with out manually filling the insert mysql query with input filed names. Function: function insert_Defined($table, $array,$ins=''){   // insert('table', array_map('trim',$_POST));     global $db;     $query = "INSERT INTO" . ' ' . $table;     $fis = array(); $vas = array();         foreach ($array as $field => $val) {         $fis[] = "`$field`";         $vas[] = ($val != "NOW()") ? "'" . mysqli_real_escape_string($db,$val) . "'" : "NOW()";     }         $query .= "(" . implode(",", $fis) . ") VALUES (" . implode(",", $vas) . ")";     //echo $query;exit;     Query($query);if(!empty($ins)){$ins_id=mysqli_insert_id($db);return $ins_id;} } Form: <form action="" method="post" name="designation&

Calculate Number of working days in a month excluding weekends(Saturday and Sunday) using PHP

The below function is used to calculate number of working days in a month. Function Calling: $no_days= rns_countDays ($row['date'],array(0, 6)); Function: function rns_countDays($date, $ignore) {      //echo countDays(array(0, 6), start_date, end_date);     $count = 0;     $ndays=0;     $now=date("Y-m-d");     $month=date("m",strtotime($date));     $year=date("y",strtotime($date));            if($month==date("m") && $year==date('y')) { //Date diff month start date to current date         $from_date = new DateTime($year.'-'.$month.'-01');         $to_date = new DateTime($now);         $days_diff=$from_date->diff($to_date); //echo $days_diff->d;         $ndays=$days_diff->format("%a");         for($i=0;$i<$ndays;$i++){             $modif = $from_date->modify('+1 day');             $weekday = $from_date->format('w');             if(in_array($weekday, $igno

Get current filename with first parameter(Query String) from URL using PHP function

Today eabhyas come up with a Query String function. This function is useful to get the Query String from URL. This Function is used to get current filename with first parameter(Query String) from URL using PHP function . Function: function rns_QueryString_first($incomingURL){     preg_match('/[^&]+/', $incomingURL, $match);     return $outgoingURL = $match[0]; } Example: $path="property_add?id=3&aa=aa&b=123"; define('RNSFIFQ', rns_QueryString_first($path)); echo RNSFIFQ; Output: property_add?id=3

Remove Duplicate QueryStrings from URL using PHP

This simple PHP function is used to Remove Duplicate QueryStrings from URL. Function: function rnsQueryString_dupremov($qstring){     if(!empty($qstring)) {     $vars = explode('&', $qstring);     $final = array();     if(!empty($vars)) {         foreach($vars as $var) {             $parts = explode('=', $var);                 $key = $parts[0];             if(!empty($parts[1])) { $val = $parts[1]; } else {$val="";}                 if(!array_key_exists($key, $final) && !empty($val))                 $final[$key] = $val;         }     }     return http_build_query($final);     } else { return false; } } Example: $path="property_add.php?id=3&aa=aa&b=123&b=123&aa=aa"; define('RNSFIWQ', property_add.'?'.rnsQueryString_dupremov($_SERVER['QUERY_STRING']));  or define('RNSFIWQ', basename($_SERVER['SCRIPT_NAME'].'?'.rnsQueryString_dupremov($_SERVER['QUE

EBS Payment Gateway PHP integration kit - Version 3-PHP Integration kit

New EBS Version 3 Integration kit , based on PHP platform, can be downloaded from the following link: https://support.ebs.in/app/ind ex.php?/default_import/Knowled gebase/Article/View/620/29/ version-3-php-integration-kit Integration Guide can be downloaded through: https://support.ebs.in/app/ind ex.php?/Knowledgebase/Article/ View/651/29/ebs_integration_ guide_301 To fetch your secret key kindly login to your merchant console panel ( secure.ebs.in ) and navigate to Account >> Settings. (Login credentials will be automatically triggered to registered email id, once the account is made LIVE from our end) Kindly note that by default your EBS account is configured to use SHA512 as the hashing algorithm in the payment page template. Method to calculate the hash for request parameters: MD5/SHA1/SHA512: Hash should be calculated for all posting parameters along with your secret key. First, all the posting parameters should be sorted in ascending order and then with the secret ke

Populate Dropdown List with Array Values in PHP

The below PHP function used to Populate HTML Dropdown List from Array Values. Function : <?php function rnsdrop_Array($arr,$selids,$title='Select'){     print"<option value='0'>".$title."</option>";     foreach($arr as $id =>$name) {     if($selids==$id && $id!=0)         print "<option value=\"".$id."\" selected>".stripslashes($name)."</option>\r\n";     else if($id!=0)         print "<option value=\"".$id."\">".stripslashes($name)."</option>\r\n";     } } ?>   The below example explains how to generate dropdown list with array values using simple PHP function.   Example: <?php $arr=array(0=>'-',1=>'East','West','North','South'); rnsdrop_Array($prop_facing, @$row['prop_facing'],"Select Property Fac

How to create a Barcode Using PHP Barcode 128 Generator

A barcode is an optical, machine-readable, representation of data, the data usually describes something about the object that carries the barcode.We will use PHP to generate Barcode in this tutorial. In this script, we are using coding which will generate barcodes in barcode format Code 128 . First, we will create index.php which will ask for the user input for which Barcode has to be created PHP Barcode Generator <fieldset><legend>Detail Informations</legend><form action="createbarcode.php" method="post"><b>Enter Your Code </b><input name="barcode" type="text" /><input type="submit" value="Create Barcode" /></form></fieldset> Now we will create createbarcode.php which will call function from Barcode code128 class for creating barcode <? php include('barcode128.php'); // include php barcode 128 class // design our barcode display echo

Common MySql Interview Questions and Answers For Experienced/Freshers

Some Common MySql Interview Questions and Answers For Experienced + Freshers Which mostly asked my interviewer during interview session, As you know MySql is highly popular relational database and good compatible with open source languages like PHP. Following list of basic Mysql question and answer surely help developers for getting new jobs. MySql Interview Questions and Answers Question: What is MySQL? MySQL is an open source relational database management system (RDBMS) that uses Structured Query Language, the most popular language for adding, accessing, and processing data in a database. Because it is open source, anyone can download MySQL and tailor it to their needs in accordance with the general public license. MySQL is noted mainly for its speed, reliability, and flexibility.   Question: Why MySQL is used? MySQL database server is reliable, fast and very easy to use. This software can be downloaded as freeware and can be downloaded from the internet   Question: In

Encode and Decode of data URLs using Base64 in PHP

base64_encode and base64_decode: (PHP 4, PHP 5, PHP 7) base64_encode — Encodes data with MIME base64 Syntax: string base64_encode ( string $data ) Encodes the given data with base64.   Example: <?php $str = 'eabhyas.blogspot.com'; echo base64_encode($str); ?> Output:   ZWFiaHlhcy5ibG9nc3BvdC5jb20= (PHP 4, PHP 5, PHP 7) base64_decode — Decodes data encoded with MIME base64 Syntax: string base64_decode ( string $data [, bool $strict = false ] ) Decodes a base64 encoded data . Example: <?php $str = 'ZWFiaHlhcy5ibG9nc3BvdC5jb20='; echo base64_decode($str); ?> Output:   eabhyas.blogspot.com Function : <? function sscb64ende($s,$t=0){     if($t==0){         $v=base64_encode($s);         $v = strtr($v, '+/=', '-_,');     } else {         $v = strtr($s, '-_,', '+/=');         $v=base64_decode($v);     } return $v; } ?>

Multidimensional Array Searching - Find key by specific value

Solution is based on the array_search() function. You need to use PHP 5.5.0 or higher. $userdb=Array ( (0) => Array     (         (uid) => '100',         (name) => 'Sandra Shush',         (url) => 'urlof100'     ), (1) => Array     (         (uid) => '5465',         (name) => 'Stefanie Mcmohn',         (pic_square) => 'urlof100'     ), (2) => Array     (         (uid) => '40489',         (name) => 'Michael',         (pic_square) => 'urlof40489'     ) ); Solution-1: function myfunction($products, $field, $value) {    foreach($products as $key => $product)    {       if ( $product[$field] === $value )          return $key;    }    return false; }   Solution-2: $key = array_search(40489, array_column($userdb, 'uid')); echo ("The key is: ".$key); //This will output- The key is: 2 The function array_search() has two arguments. The first one is the value that yo

Document Expired or Webpage has expired on back button

If you have a dinamic website and want to allow your visitors to use the back button after they sent a form with the post method, the best combination I found was: <?php header("Expires: Sat, 01 Jan 2000 00:00:00 GMT"); header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); header("Cache-Control: post-check=0, pre-check=0",false); session_cache_limiter("must-revalidate"); // and after you start the sessionsession_start(); ?> I try some combinations using header("Cache-Control: no-cache, must-revalidate"), but when clicking the back button, the last changes in the form back to their previous states. The combination above works fine with IE 6.x. I didn't test this with other browsers. When I try something like session_cache_limiter("nocache, must-revalidate") it doesn't work. The page only updates when I used the browser's refresh button. In dynamic web sites this is not g

CodeIgniter Top 50 Interview Questions and Answers

1) Explain what is CodeIgniter? Codeigniter is an open source framework for web application. It is used to develop websites on PHP. It is loosely based on MVC pattern, and it is easy to use compare to other PHP framework. 2) Explain what are hooks in CodeIgniter? Codeigniter’s hooks feature provides a way to change the inner working of the framework without hacking the core files. In other word, hooks allow you to execute a script with a particular path within the Codeigniter. Usually, it is defined in application/config/hooks.php file. The hooks feature can be globally enabled/disabled by setting the following item in the application/config/config.php file: $config[‘enablehooks’] = TRUE; 3) Explain how you will load or add a model in CodeIgniter? Within your controller functions, models will typically be loaded; you will use the function $this->load->model (‘Model_Name’); 4) Explain what helpers in CodeIgniter are and how you can load a helper file? In CodeIgniter,