Sunday, 13 December 2015

send UTF sms through php using cdac service

Before using the sms service we must first install PHP5_CURL as we are using curl function

Command to install is : sudo apt-get install php5-curl

then after restart the apache server:
              sudo   /etc/init.d/apache2 restart

If the above step not done we will receive a error " CALL TO UNDEFINED FUNCTION CURL_INIT"

and, if it is executed in browser you may receive 500 - server error.

So, before proceeding please install the above step.


<?php 
header('Content-Type: text/html; charset=UTF-8');
// $message = "नमस्कार सुभोदय";
// $message = "�� �� मु�्य समा�ार";
$message="ఇది టెస్ట్ మెసేజ్";
$finalmessage = "";
$sss = "";
for($i=0;$i<mb_strlen($message,"UTF-8");$i++) {
$sss=mb_substr($message,$i,1,"utf-8");
$a=0;
$abc="&#" .ordutf8($sss,$a).";";
$finalmessage.=$abc;
}
echo $finalmessage;
function ordutf8($string, &$offset){
$code=ord(substr($string, $offset,1));
if ($code >= 128) 
{ //otherwise 0xxxxxxx
if ($code < 224) $bytesnumber = 2; //110xxxxx
else if ($code < 240) $bytesnumber = 3; //1110xxxx
else if ($code < 248) $bytesnumber = 4; //11110xxx
$codetemp = $code - 192 - ($bytesnumber > 2 ? 32 : 0) - ($bytesnumber > 3 ? 16 : 0);
for ($i = 2; $i <= $bytesnumber; $i++) {
$offset ++;
$code2 = ord(substr($string, $offset, 1)) - 128; //10xxxxxx
$codetemp = $codetemp*64 + $code2;
}
$code = $codetemp;
}
return $code;
}
$data = array(
"username" => "XXXXXX", // type your assigned username
"password" => "XXXXXXX", //type your password
"senderid" =>"XXXXXX", //type your senderID
"smsservicetype" => "unicodemsg", 
"bulkmobno" => "97305XXXXX,762067XXXX",//*Note*:for single number enter one number
"content" => $finalmessage //type the message.

);
function post_to_url($url, $data) {
$fields = '';
foreach($data as $key => $value) {
$fields .= $key . '=' . urlencode($value) . '&'; 
}
rtrim($fields, '&');
$post = curl_init();
curl_setopt($post, CURLOPT_URL, $url);
curl_setopt($post, CURLOPT_POST, count($data));
curl_setopt($post, CURLOPT_POSTFIELDS, $fields);
curl_setopt($post, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded"));
curl_setopt($post, CURLOPT_HTTPHEADER, array("Content-length:" . strlen($fields) ));
curl_setopt($post, CURLOPT_HTTPHEADER, array("User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)"));
curl_setopt($post, CURLOPT_RETURNTRANSFER, 1);
echo $result = curl_exec($post);
curl_close($post);
}
post_to_url("http://msdgweb.mgov.gov.in/esms/sendsmsrequest", $data);
?>
   

Sending E MAIL using PHPMailer

Download the PHPMailer from the website before proceeding : https://github.com/PHPMailer/PHPMailer

Extract the ZIP file and keep in the same location where our sendMail.php residing ( the apache/xampp default location) and

Now here is the sendMail.php , copy the below code and paste it in a file,name the file as sendMail.php. Change the Mail domain name, username and passwords respectively at the locations given and run the program using the command

> php sendMail.php

Then check the output in your inbox.


<?php
                                           /* Send Mail through PHP code */
try{
require_once('PHPMailer/class.phpmailer.php');

$mail = new PHPMailer();
// Dialog::message('Mail', "Mail object created with $this->email");
// $uname=Yii::app()->user->name;  No need if this is not a webapplication ( The logged in username say example, Admin)
$mail->IsSMTP();
$mail->CharSet="UTF-8";
$mail->SMTPSecure = 'ssl';
$mail->Host = 'mail.domain.in';
$mail->Port = 465;
$mail->Username = 'username@domain.in';
$mail->Password = 'password@123';
$mail->SMTPAuth = true;
$mail->From = 'username@domain.in';
$mail->FromName = "Email";
$mail->AddAddress('username@domain.in');

$mail->AddReplyTo("Someone@domain.in", "someone");
//$ipadd=Yii::app()->request->userHostAddress;
$ipadd=null;
$mail->IsHTML(true);
$mail->Subject = "Testing the mail service";
$mail->AltBody = "Mail From Server. To view the message, please use an HTML compatible email viewer!";
$mail->Body = "From Email : username@domain.in <br/> Logged in Application as <b>Admin</b>";


if(($ipadd!=null)and($ipadd!='')) {
// $mail->Body= $mail->Body." through Ip address $ipadd<br/> Content: ".$this->body;
$mail->Body= $mail->Body." through Ip address $ipadd<br/> Content: Testing the application using XAMPP";
}
else {
// $mail->Body= $mail->Body."<br/> Content: ".$this->body;
$mail->Body= $mail->Body."<br/> Content: Test mail from the XAMPP server code";
}
if(!$mail->Send())
{
 echo "<h1>"."Mailer Error: " . $mail->ErrorInfo."</h1>";
 exit(0);
}
else
{
 echo "<h1>Mail sent Successfully!</h1>";
}
     }catch(Exception $e){
        echo 'caught exception:',$e->getMessage();
     }

     ?>

Thursday, 10 December 2015

Got Error "C:\users\..\AppData\Local\Temp;c:" while installing a software

err.jpg
If you encounter the above error while installing a software, Do the following steps:
The above error encounters when the user defined environment variable "TEMP" is updated. For example, If we installed JDK , the main important part after installing JDK is setting PATH .. somehow, for some need we need to set TEMP variable also, In that case, this TEMP variable creates the error while installing since the ":" is not allowed in the folder names and here in path we have a ';' followed by 'C:' generates a windows error 
Your %TEMP% environment variable is screwy.  Do this:
- Open Control Panel
- System
- Advanced System Settings
- Environment Variables
- In the User Variables, select TEMP and click Edit
- Remove the semi-colon (;) and everything after it
- OK your way out of all the dialogs
- Try installing Software again
Hope this helps!!!

Monday, 23 November 2015

Install Google Chrome in UBUNTU

If it is 64 bit OS follow the below steps

wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add - 
sudo sh -c 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
sudo apt-get update 
sudo apt-get install google-chrome-stable 
 
 
For 32-bit systems user can use this code:

sudo apt-get install libxss1 libappindicator1 libindicator7 
wget https://dl.google.com/linux/direct/google-chrome-stable_current_i386.deb 
sudo dpkg -i google-chrome*.deb 
 
If error messages pop up after running the command
sudo dpkg -i google-chrome*.deb

then run the command

sudo apt-get install -f 
 
and then re-run the previous command. The error messages mentioned should include something similar to

google-chrome-stable depends on [lib-example]; however; Package [lib-example] is not installed. 
 
This installs a needed library for Google Chrome, then downloads the latest version of Chrome to a temporary directory and installs it. Run google-chrome to start the browser.
During the installation a PPA is added to your system so that Google Chrome receives the latest updates whenever you check for system updates.

Friday, 13 November 2015

Install Sublime editor in ubuntu

Type the following commands in the terminal, for Sublime Text 2 :

sudo add-apt-repository ppa:webupd8team/sublime-text-2
sudo apt-get update
sudo apt-get install sublime-text
 
For Sublime Text 3 :

sudo add-apt-repository ppa:webupd8team/sublime-text-3
sudo apt-get update
sudo apt-get install sublime-text-installer

Saturday, 31 October 2015

Start XAMPP Server automatically on windows Startup

Follow the Steps:-

1) First you need to configure your xampp setting. RUN XAMPP and follow image.



2) Now, to run any exe at the start up. Windows need to see the Run log. Exe file present in the RUN.log windows runs those files.

3) So to start Xampp. We have to make its log in RUN.

4) windows + R (i.e Open RUN) type REGEDIT >HKEY_LOCAL_MACHINE>SOFTWARE>
     MICROSOFT>WINDOWS>CURRENT VISION>RUN.






5)Now right click in window> NEW>STRING VALUE or alt+ E > NEW>STRING VALUE. it will add new file in list. name it by XAMPP. 

6) Right Click on this File. Select MODIFY> in String Data field type path of xampp_start.exe
c:\xampp\xampp_start.exe > click on ok.






7) Now LOG OFF . Again on LOG ON you will find your Xampp started automatically.


8) It will now even show any xampp window running or minimized.  Check it by running  any PHP file in browser. 

Thursday, 17 September 2015

12 Reasons to Choose PHP for Developing Website

The Internet industry has been revolutionizing numerous technologies for the betterment. Most web developers choose PHP to design their own website. The main reason is it is an open-source server-side scripting language that provides multifarious features. 
 
It is also an interpreted script language best suited for developing websites as per your preferences. Further, PHP is highly beneficial for its users since it is compatible with both Windows and Unix-based operating systems. It also enables the users to easily manage and upgrade their PHP based websites without any burdens. 
 
If you are looking to create a website then choose PHP to build exceptional quality websites and web applications effortlessly. Execution of a wonderful websites can easily be achieved with the support of expert PHP developers who have vast experience in the online industry.

This blog is very useful for the users as it contains various information on why to choose PHP over other languages! Let’s have a look on the reasons why PHP is extensively used for website development. 

1. User – friendly 

 
PHP is absolutely simple to comprehend than other programming languages. Since it is an easy and powerful language, it has been widely used for creating web based applications that requires utmost functionality with minimal coding. In addition, PHP based web applications are extremely secure as compared to applications of various other programming languages.
  

2. Flexibility 

 
This is a one only language that provides maximum level of flexibility as compared to languages like Asp, .Net and etc. It is ideal for any users who look to extend the high-end programming language to exactly match the custom requirements of any businesses.
Moreover, it is open source software which allows the user to use any editor to write the code. It can also be combined with diverse libraries such as graphics and Extensible Markup language (XML) and etc. 
 

3. Dynamic


It is an effective language enables you to develop lively websites which refresh automatically. Using PHP for creating websites may not require any updates manually for refreshing it. PHP web development includes a various interesting process that mesmerizes the users.

4. Cost Effective


PHP is being widely used by an extensive range of users for the past 2 years as it is economic for developing a website efficiently. Besides, it can easily be obtained free of charge from the internet. The users can also download the latest version for free of cost at any time. It is highly beneficial for web developers who strive to make a new entry in the online market.  

5. Data Processing 

 
Developing any website using PHP supports the user to include fast data processing features. It also helps to improve the website functions to a greater extent.

6. Open Source


PHP is universally recognized open source language which provides ultimate solutions for all website development needs. The reason behind the success of this high end language is, it is totally free and simple to use.

7. High Performance 


PHP is a unique language that completely improves speed of development, rather increasing the speed of execution. It operates on a conventional web stack. PHP makes full use of Apache web server. Likewise, PHP applications utilize Apache web server as well as the MySQL database.

8. Cross Platform


Now, it is quite easy to create cross-platform applications with PHP since it works amazing on UNIX, LINUX and Windows platforms. It is developed in such a way that it interfaces with Apace and MYSQL. If you are interested to develop a cross platform application, PHP is the right choice.

9. Prominent in CMS


Any websites that has been developed from PHP are fully customized and assists the programmers to develop websites as per their clients’ preferences.

10. Embedding Qualities


One of the superior qualities of PHP language is that it can easily be embedded into HTML within a very few steps. This is an exemplary language supports web programmers to convert an existent static website into a whole new active one.

11. Extensions


Being a flexible and innovative language, it provides many numbers of extensions. The output of this language is fully significant and helps the users to determine their return on investment.

12. Instant


This is considered as a fast and instant language which caters quick turnaround time. By employing a well experienced PHP developer, you can obtain a prompt solution that you want to achieve for a very long time. 

These are some of the main reasons why all the web developers choose PHP over other languages for creating an unimaginable PHP web development projects.

Thursday, 13 August 2015

working with PHP and MYSQL dates

$dt=date('d/m/Y');                                                                // Gives Todays date  
            
$day = date('w');                              // Gives week day number  sun-sat is 0-6, sunday is zero
$sday = $day - 0;  // Last sunday
$eday = 7 - $day;  // Next sunday

$ws = date('d/m/Y', strtotime('-'.$sday.' days'));
$lastsunday = date('d/m/Y', strtotime('-'.$sday.' days'));

$we = date('d/m/Y', strtotime('+'.$eday.' days'));
$nextsunday  = date('d/m/Y', strtotime('+'.$eday.' days'));

$no_of_mand=16;

$chkrep = mysql_result(mysql_query("SELECT IFNULL(count(*),0) FROM meerepdone where
        STR_TO_DATE(tdate,'%d/%m/%Y')>=STR_TO_DATE('$ws','%d/%m/%Y') and
        STR_TO_DATE(tdate,'%d/%m/%Y')<=STR_TO_DATE('$we','%d/%m/%Y')"),0);

if($chkrep==0) // The week records exists in DB or not
{

echo "<br/><br/><center><font color='darkblue'><h2>There are no Records in this week in DB</h2></font>
 </center>";
 echo "<br/><br/><center><font color='darkblue'><h2> FROM DATE : $ws - To date : $we</h2></font>
 </center>";
 exit(0);
 
}

////////////////////////////////////////////////////////////////////////////////////////////////////////

/* $query="SELECT distinct tdate from meerep where
        STR_TO_DATE(tdate,'%d/%m/%Y')>=STR_TO_DATE('$ws','%d/%m/%Y') and
        STR_TO_DATE(tdate,'%d/%m/%Y')<=STR_TO_DATE('$we','%d/%m/%Y')"; */

$initqry=mysql_result(mysql_query("SELECT IFNULL(count(*),0) FROM fortnight where 
        STR_TO_DATE(fromdt,'%d/%m/%Y')=STR_TO_DATE('$ws','%d/%m/%Y') and  
        STR_TO_DATE(todate,'%d/%m/%Y')=STR_TO_DATE('$we','%d/%m/%Y')"),0);

/* the above Query compares the php dates with mysql dates */


if($initqry==0){

$transqry = "SELECT DISTINCT mandal from meerep";
$res=mysql_query($transqry);
$nor=mysql_numrows($res);
$i=0;$mand='';
$iconn = new mysqli($servername, $username, $password, $database);
while($i<$nor){
$mand=mysql_result($res,$i,"mandal");
$insqry = "INSERT INTO fortnight(mandal,fromdt,todate) VALUES('$mand','$lastsunday','$nextsunday')";

$iconn->query($insqry);
  $i++;
}
$iconn->close();

$query = "SELECT DISTINCT mandal from meerep";
$result=mysql_query($query);
$num=mysql_numrows($result);
$i=0;
$sl=1;$mand='';
$getpendper = 0;
$weekper = 0;
$iconn = new mysqli($servername, $username, $password, $database);
while($i<$num){

 $mand=mysql_result($result,$i,"mandal");
 $minper = mysql_result(mysql_query("SELECT IFNULL(MIN(pendper),0) FROM meerep where
        STR_TO_DATE(tdate,'%d/%m/%Y')>=STR_TO_DATE('$lastsunday','%d/%m/%Y') and
        STR_TO_DATE(tdate,'%d/%m/%Y')<=STR_TO_DATE('$nextsunday','%d/%m/%Y') and  mand=trim('$mand')"),0);
 $maxper = mysql_result(mysql_query("SELECT IFNULL(MAX(pendper),0) FROM meerep where
        STR_TO_DATE(tdate,'%d/%m/%Y')>=STR_TO_DATE('$lastsunday','%d/%m/%Y') and
        STR_TO_DATE(tdate,'%d/%m/%Y')<=STR_TO_DATE('$nextsunday','%d/%m/%Y') and  mand=trim('$mand')"),0);

 $weekper = 100 - round(($minper/$maxper) * 100) ;   // calculating percentage

 $updqry = "UPDATE fortnight SET percen='$weekper' WHERE mandal='$mand' and fromdt='$lastsunday' and todate='$nextsunday'";

 $iconn->query($updqry);                          /* A simple Update through PHP */ 
 $i++; $sl++;
}                      // End of While loop

$iconn->close();

}            // End of If condition fortnight having zero records for the week dates

creating dynamic arrays and dynamic variables example in php

<?php

$test = array();                                           //  The Dynamic array declaration
$i=0;
$nl = array("abc","yzc","ijk");                  // Static array

for($i=0;$i<3;$i++){
echo $nl[$i]."\n";                                // Displaying static array
}

/* Gives out put as
abc
yzc
ijk


*/

for($i=0;$i<3;$i++){
$test[$nl[$i]]="number:".$i + 1;      
${"file" . $i} = "test $i";

}

var_dump($test);

/* Gives output as

array(3) { ["abc"]=> int(1) ["yzc"]=> int(1) ["ijk"]=> int(1) } 

*/


echo "<br/>".$test["yzc"];     // Output is one i.e., 1

for($i=0; $i<=2; $i++) {
echo "<br/>".${"file".$i};
}

/* Gives output as

test 0
test 1
test 2


*/

?>

Thursday, 30 July 2015

Adding and Subtracting Dates and Times in PHP

$today = date(‘d/m/Y’);  // Todays date in date/month/4 digit year format

$yesterdaydt=date(‘d/m/Y’,strtotime(“-1 days”));  // GET Yesterdays Date


Subtracting days from a date

The following example will subtract 3 days from 1998-08-14. The result will be 1998-08-11.

$date = "1998-08-14";                                    
$newdate = strtotime ( '-3 day' , strtotime ( $date ) ) ;
$newdate = date ( 'Y-m-j' , $newdate );                  
echo $newdate;                                           
 
Subtracting Weeks from a date

The following example will subtract 3 weeks from 1998-08-14. The result will be 1998-07-24. Notice that the only difference in the code is the week statement.

$date = "1998-08-14";                                     
$newdate = strtotime ( '-3 week' , strtotime ( $date ) ) ;
$newdate = date ( 'Y-m-j' , $newdate );                   
echo $newdate;                                            
 
Subtracting Months from a date

The following example will subtract 3 months from 1998-08-14. The result will be 1998-05-14. Notice that the only difference in the code is the month statement.

$date = "1998-08-14";                                      
$newdate = strtotime ( '-3 month' , strtotime ( $date ) ) ;
$newdate = date ( 'Y-m-j' , $newdate );                    
echo $newdate;                                             
 
Subtracting Years from a date

The following example will subtract 3 years from 1998-08-14. The result will be 1995-08-14. Notice that the only difference in the code is the year statement.

$date = "1998-08-14";                                     
$newdate = strtotime ( '-3 year' , strtotime ( $date ) ) ;
$newdate = date ( 'Y-m-j' , $newdate );                   
echo $newdate;                                            
 
Adding days, months, weeks and years from a date

There isn’t really much difference from subtracting and adding dates. To add dates, just use any of the examples above and replace the negative (-) with a positive (+) e.g. ‘+3 weeks’
You could also just do:
echo date(“Y-m-j”, strtotime(“1998-08-14 -3 days”));
(sub days, weeks, months, as needed)

This adds 2 days to the current date:
 
$date = date('Y-m-j');                                   
$newdate = strtotime ( '+2 day' , strtotime ( $date ) ) ;
$newdate = date ( 'Y-m-j' , $newdate );                  
echo $newdate;                                           
 
This adds 2 months to the current date:
 
$date = date('Y-m-j');                                     
$newdate = strtotime ( '+2 month' , strtotime ( $date ) ) ;
$newdate = date ( 'Y-m-j' , $newdate );                    
echo $newdate;                                             
 
This adds 2 years to the current date:
 
$date = date('Y-m-j');                                    
$newdate = strtotime ( '+2 year' , strtotime ( $date ) ) ;
$newdate = date ( 'Y-m-j' , $newdate );                   
echo $newdate;                                            

This subtracts 6 hours from the current date:
 
$date = date('Y-m-j');                                    
$newdate = strtotime ( '-6 hour' , strtotime ( $date ) ) ;
$newdate = date ( 'Y-m-j' , $newdate );                   
echo $newdate;                                            

This subtracts 10 minutes from the current date:
 
$date = date('Y-m-j');                                       
$newdate = strtotime ( '-10 minute' , strtotime ( $date ) ) ;
$newdate = date ( 'Y-m-j' , $newdate );                      
echo $newdate;                                               

If you want to change if from the current date, then simple replace the current date with the desired one…

This adds 1 year to the date 2012-11-25:
 
$date = date('2011-11-25');                               
$newdate = strtotime ( '+1 year' , strtotime ( $date ) ) ;
$newdate = date ( 'Y-m-j' , $newdate );                   
echo $newdate;                                            

Get the Week Start Date and ENd date 

Consider today is a saturday for the given example

$day = date('w');                                                             // Gives Day of week, returns 6 if it is saturday
$sday = $day - 1;                                                            // I need only working dates mon-sat so 6-1=5 
$eday = 6 - $day;                                                            // Excepting sunday in the list                           
$ws = date('d/m/Y', strtotime('-'.$sday.' days'));            // -5 days to current date that is monday            
$we = date('d/m/Y', strtotime('+'.$eday.' days'));          // + 0 days  to current date that is today - sat      
$lastsunday = date('d/m/Y',strtotime('-'.$day.' days'));  // Gives last week sunday date                           
$comingsunday = date('d/m/Y',strtotime('+'. 7-$day.' days')); // coming sunday                                    

like wise we can get any day of the week , note that the return result is a string

Code for Subtracting a day from given date 

$date = '09/02/2015';
$day_before = date( 'm/d/Y', strtotime( $date . ' -1 day' ) );
echo "<br/><br/>";
$db = date('d/m/Y',strtotime($day_before));

echo $db;

Wednesday, 29 July 2015

STOP loading previous pages when chrome browser started in ubuntu

While Google gets to work fixing the Chrome battery drain issue affecting Windows users, an easy interim solution may help preserve laptop battery life in the meantime.
The fix? Closing the browser when it’s not needed.

Captain Obvious

Historically, closing an application in Windows is straightforward: you click or tap on the ‘x’ window control button.
Depending on your settings, this isn’t always the case with Chrome; closing doesn’t always mean it fully exits. The browser often continues to run in the background on Windows (and Linux) – something you might never notice.

The Reason Why: You

Whether this happens or not depends on the sort of applications and extensions you have installed in Chrome. Some of these will “ask” the browser to stay awake so that they can continue to function; e.g., to deliver notifications of new e-mail messages or keep an active IRC chat alive.
Google makes it easy to tell when background apps are active: just look for the Google Chrome icon in the system tray (bottom right corner of your desktop screen). Click on this emblem to view a list of active tasks and a access a proper ‘Exit’ option.
If want to stop Chrome from running in the background entirely (i.e., so that it always exits when closed), regardless of extension, you can. You just need to tell it to.

How to Stop Chrome Running in the Background

On Windows or Linux click on the Chrome icon in the task bar/system tray, find the ‘Let Chrome run…’ option and click/tap it to disable/toggle the checkmark off.
It’s that simple. 
The behaviour can also be changed through the browser’s main settings page:
  • Click on the Chrome menu (or press Alt+E)
  • Select Settings
  • Click on the link titled ‘Show advanced settings
  • Under the section headed ‘System‘ untick the box next to “Continue running background apps when Google Chrome is closed”
To reenable the feature simply repeat the steps above but reversing the final step.