Skip to main content

Posts

Showing posts from 2016

Cakephp 3.x cake bake on linux system

How to Cakephp 3.x cake bake on linux system Cakephp gives an awesome feature that is bake. by using bake you can create controller models and views without coding . you just need to type some commands and cake will create files for you. So here is the simple steps for cake bake in cakephp 3.x on linux system 1.First Open your terminal window 2. install php5 on your system by using this command and press enter       sudo apt-get install php5-mysql 3. Now download letest cakephp 3.x zip file from cakephp github and unzip into your local server (ex. /op/lampp/htdocs/newcake/here all files) 4. Now in terminal change directory by this command and press enter       cd /opt/lampp/htdocs/newcake/ 5. Then run following command   bin/cake bake When you hit enter then you will see output like this  Welcome to CakePHP v3.3.4 Console --------------------------------------------------------------- App : src Path: /opt/lampp/htdocs/zcake/src/ PHP : 5.5.9-1ubuntu

Simply Create PDF with PHP mysql FPDF (2 steps)

Simply Create PDF with fpdf Sometimes we need to generate pdf based on mysql database so here is the example of How to create PDF with PHP mysql using FPDF in 2 Steps. Step1 First Download fpdf from Here Step 2 Create an index.php file and paste this code <?php include('../config.php'); require('webroot/fpdf/fpdf.php'); $aClassDb = new ClassDb(); class Getdata { public function all($getPostdata) { $getData = ""; try { $getApartment = $getPostdata['apartid']; $getYear = $getPostdata['invoiceyear']; $startdate = mktime(0,0,0,1,1, $getYear); $enddate = mktime(0,0,0,12,31, $getYear); $query = $aClassDb->getAllData("invoice", "AND appartment='$getApartment' AND date_invoice BETWEEN $startdate AND $enddate"); $getData = $query; /* PDO $db = new PDO('mysql:host=localhost;dbname=test;', 'root'

Change page title with jquery

How to Change title with jQuery Change Document title with jQuery Here is the all ways that you can use to change title of webpage THE BEST METHOD TO CHANGE TITLE WITH JQUERY <script type="text/javascript">  document.title = "New Dynamic Title with Jquery"; </script> You just need one line to change document title dynamically. you can also update document title dynamically with this method. Other Methods METHOD 1 - <script type="text/javascript">   $('html head').find('title').text("New Dynamic Title with Jquery"); </script> METHOD 2 - <script type="text/javascript">   $(document).attr("title", "New Dynamic Title with Jquery"); </script> METHOD 3- //Not Supported in IE <script type="text/javascript"> $(document).ready(function() {       $(this).attr("title", "sometitle");    });

Upload files and folders on GitHUB [tutorial]

Upload files and folders on GitHUB To upload your project or files and folder on github with files and folder on linux system you have to follow these simple steps. Open Console by Ctrl+Alt+T First make the repository (Name=RepositoryName) from your profile page-> repository tab and click on New button  on github. Open the terminal and make the new directory (mkdir NewDirectory) or create manually a new folder or directory. Copy your ProjectFolder to this NewDirectory. Change the present work directory to NewDirectory.              cd NewDirectory Run the following command one by one       git init       git add ProjectFolderName       git commit -m "first commit"       git remote add origin https://github.com/YourGithubUsername/RepositoryName.git       git push -u origin master If console window show error something like this  ! [rejected]        master -> master (fetch first) error: failed to push some refs to 'https://github.c

Upload Large CSV into mysql in a minute PHP Script

How to upload large CSV file in Mysql Database within a minute [ PHP SCRIPT ] IF you have large csv file and you want to upload in Mysql then mysql will take too much time to import that csv data . so here is the script that will  take less a minute and all csv data will uploaded in mysql. This Script contains a html form you have to fill information of your database and also insert file name in "Name of the file" column and also notice that your file and this script must be exist in same folder. SO here is the PHP script to upload large CSV file in mysql within a minute. <?php if(isset($_POST['username'])&&isset($_POST['mysql'])&&isset($_POST['db'])&&isset($_POST['username'])) { $sqlname=$_POST['mysql']; $username=$_POST['username']; $table=$_POST['table']; if(isset($_POST['password'])) { $password=$_POST['password']; } else { $password= ''; } $db=$_POST[&

Simply Create Excel Spreadsheets in PHP without using any library

Simply Create Excel Spreadsheets in PHP In PHP , create excel Spreadsheets of database data we only need to set headers. header("Content-Type: application/vnd.ms-excel"); and header("Content-disposition: attachment; filename=city.xls"); The First header we need to set content type ms-excel . The Second header will make file downloadable. when we run this file into browser then browser will ask to download xls file. Example 1 echo 'Name' . "\t" . 'Address' . "\t" . 'Contact' . "\n"; echo 'Coderain' . "\t" . 'Internet' . "\t" . '111111111' . "\n"; Explaination Example 1 will add Name , Address , Contact column into excel as a header of excel file. then you can add data after this. \t = \t is used for end current tab or column and go to the next tab or column. \n = \n is used for go to next Row or Line. Here is the complete example of create excel file of

Show popup at once Bootstrap Jquery

 Show popup at once Bootstrap Jquery  Sometimes we want to show login signup or welcome popup at once to per user . we can show popup at once to user by using jQuery .  We can show popup at once with jquery using two methods  1. localStorage- localStorage is relatively new concept that stores data with no expiration date on client side.  2. Cookies - Cookies also stores data on client side but the main difference between localStorage and Cookies is that Cookies can manipulated from the server side.  For our example we are using Bootstrap Modal Popup .to use Bootstrap Modal Popup you should call bootstrap js and css class. <!-- BootStrap Modal Popup --> <button type="button" id="btntpr" class="btn btn-info  btn-lg" data-toggle="modal" data-target="#signupnow">Open Modal</button> <!-- Modal --> <div id="signupnow" class="modal fade" role="dialog">   <div class=

Select query in cakephp 3.x

Select query with multiple where conditions in cakephp 3.x First include these classes into your controller to use objects of these classes use Cake\ORM\Query; use Cake\ORM\Table; use App\Model\Entity\Role; use Cake\ORM\TableRegistry; Simple Select query in cakephp 3.x  $tableRegObj = TableRegistry::get('OurTableName');  //database Table name = our_table_name  $getAllResults = $tableRegObj->find('all');  $getAllResults will return results object . if you want to count records then you can use count function of this  example =>  echo $getAllResults->count();  If you want fetch data as an array then you can use toArray();  example =>  $getAllResults = $tableRegObj->find('all')->toArray();  If you want to fetch only first row of result data then you can use first()  example=>  $getFirstRow = $getAllResults->first();  2.Fetch Data with conditions       In cakephp 3.x you can use multiple conditions with fetch

How to use Google reCaptcha with Cakephp 3.x

How to use Google reCaptcha with Cakephp To use google reCaptcha with php you can read How to use google recaptcha with PHP . In this tutorial we learn how to use google recaptcha with cakepphp 3.x we need two keys that provide by google .you can get your recaptcha keys from google developer account. 1.first we need to call google recaptcha js so open your projectFolder/src/template/layout/default.ctp or you can call it into your header.ctp <?= $this->Html->script('https://www.google.com/recaptcha/api.js') ?> 2. Now we have to save keys into our project that we can access from anywhere so copy this code and paste it into YourProject/Config/bootstrap.php   Configure::write('google_recatpcha_settings', array(     'site_key'=>'SITEKEY',     'secret_key'=>'SECRETKEY' )); 3.Now open your appConteoller (projectFolder/src/Controller/AppController) Add these code into initialize function of appController public functi

How to Use Bootstrap datepicker

How to Use Bootstrap datepicker bootstrap provides simple and attractive datepicker widget that we can use in html page wihtout any problem  to use bootstrap datepicker with html or php we need to call cdn datepicekr js. INDEX.HTML  <div class="container-fluid">   <div class="row">    <div class="col-md-6 col-sm-6 col-xs-12">     <!-- Form code begins -->     <form method="post">       <div class="form-group"> <!-- Date input -->         <label class="control-label" for="date">Date</label>         <input class="form-control" id="date" name="date" placeholder="MM/DD/YYY" type="text"/>       </div>       <div class="form-group"> <!-- Submit button -->         <button class="btn btn-primary " name="submit" type="submit">Submit</button>      

Using Node.js and Websockets in Cakephp 3.x

  Using Node.js and Websockets in Cakephp 3.x Node.js is a platform built on Chrome’s JavaScript runtime to make building applications in JavaScript that run on the server .Node.js is the latest technology that used for create realtime applications and with cakephp we can use to send updated data to each connected clients. The main advantage of node.js is that you don't need to refresh a webpage or create ajax requestto update users data. Websockets And Node.js is the great combination to update data from server side to client side. so here is the tutorial for how to use node.js and websockets in cakephp 3.x. 1. First we need to install node.js on server. you can follow this tutorial to How to Install Node.js .  2. Then you need to install Socket.io on your server.to install socket.io on your server you nedd to run this command. sudo apt-get npm install socket.io 3. After installation of Socket.io we are ready to use node.js and websockets with cakephp . 4.

clear ajax requests from browser console

How to clear ajax requests from browser console  Yes we can clear ajax requests from mozilla firefox console tab .to clear ajax requests from console we use javascript function function clearconsole() {   console.log(window.console);   if(window.console || window.console.firebug) {    console.clear();   } } when you call this function after your ajax request then all ajax request from console will be hide . call this function after ajax success , done or fail . Example             $.ajax({                         type:"POST",                          url: form.attr('action'),                         data:form.serialize(),                         dataType: "json",                         success: function(response){                           if(response.msgtype=="success")                           {                              clearconsole();                            }                      });

How to do PHP unserialize jQuery serialized form data

How to do PHP unserialize jQuery serialized form data   The Jquery serialize method just takes the form elements and puts them in string form. example - "firstvariable=value&secondvariable=othervalue"; if you are not using associative array then you can access this variable by $_GET and $_POST method. Example =  $variable1 = $_GET[' firstvariable '];  but if your data in an array then you need to unserialize jquery serialized data in php. you can unserialize jquery seralized data by usin this methods. you can unserialize jquery serialize data into php by using parse_str. //GET METHOD $params = array (); parse_str ( $_GET , $params );   //POST METHOD $params = array (); parse_str ( $_POST , $params );   if your data serialize data in a variable then you need to use-    $params = array(); parse_str($_POST['formdata'], $params);     you can also use this function to unserialize your data   function unserializeForm ( $

Tutorial-formatting floating point numbers in javascript

How to formatting floating point numbers in javascript In jQuery or javascript when we add or multiple or any mathematical opertaion perform on floating point numbers it gives wrong output . For Example if we add 0.1+0.2 using javascript it gives  0.30000000000000004 instead of 0.3 . so here is the solution of perform mathematical operations on floating point numbers with javascript. We are using 2 js function for this 1. parseFloat   2. toPrecision javascript snippet to solve js floating point numbers wrong output problem. <script> function cal() {  var a=0.1;  var b=0.2;  var c=parseFloat((a+b).toPrecision(10)); //Calculate like this  alert("parseFloat((0.1 + 0.2).toPrecision(10)) = "+c); } </script>

Get your gmail emails using php

How to get your gmail emails using php here is the short n simple script to get your gmail inbox messages and you can store them into your database . $imapPath = '{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX';  $username = 'your-mail@gmail.com'; $password = 'your-password'; // try to connect $inbox = imap_open($imapPath,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error()); $emails = imap_search($inbox,'UNSEEN'); $output = ''; foreach($emails as $mail) {         $headerInfo = imap_headerinfo($inbox,$mail);         $output .= $headerInfo->subject.'<br/>';     $output .= $headerInfo->toaddress.'<br/>';     $output .= $headerInfo->date.'<br/>';     $output .= $headerInfo->fromaddress.'<br/>';     $output .= $headerInfo->reply_toaddress.'<br/>';         $emailStructure = imap_fetchstructure($inbox,$mail);         if(!isset($em

Solved-mail not send gmail smtp phpmailer

Solved-mail not send with phpmailer if you face problem to send mail from your localhost or live server you can use this code to solve your problem. function SendMail( $ToEmail,$subjectval, $MessageHTML, $MessageTEXT ) {      // require_once ( 'class.phpmailer.php' ); // Add the path as appropriate      include_once "webroot/phpmailer/PHPMailerAutoload.php";       $Mail = new PHPMailer();       $Mail->IsSMTP(); // Use SMTP       $Mail->Host        = "smtp.gmail.com"; // Sets SMTP server       $Mail->SMTPDebug   = 0; // 2 to enable SMTP debug information       $Mail->SMTPAuth    = TRUE; // enable SMTP authentication       $Mail->SMTPSecure  = "tls"; //Secure conection       $Mail->Port        = 587; // set the SMTP port       $Mail->Username    = 'yourmailaddress@gmail.com'; // SMTP account username       $Mail->Password    = 'yourpassword'; // SMTP account password       $Mail->Priority   

Send mail from localhost using phpmailer

 How to Send mail from localhost using phpmailer   To send mail from your localhost or live server you can use phpmailer class. phpmailer class sends mail using smtp from both local and live server .using phpmailer you can also send html. so these are the steps to send a mail from localhost using phpmailer. Step 1 First download phpmailer class from here . and after download unzip and extract it into your root directory ex(htdocs/yourprojectfolder/phpmailer/). Step 2 then create a form in your html to send mail    <form action="" method="post" onsubmit="return sendnewsletter()">                                                       <div class="form-body">                                 <div class="form-group">                                     <div class="msgalert"><?php echo isset($msgshow)?$msgshow:""; ?></div>                                  </div>       

Simple n secure data Encryption and Decryption function using php

Simple Encryption and decryption function in php we use mcrypt php function to encrypt a string and decrpyt the same string.so these are the function to encypt and decrypt a string in php. Php function to encrypt a string.  public function encryptHash($value)       {         $key = 'wt1U5qZAWJFYUGenFoMOiLwQrGLgdbHA';         $iv = mcrypt_create_iv(                 mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC),                 MCRYPT_DEV_URANDOM             );             $encrypted = base64_encode(                 $iv .                 mcrypt_encrypt(                     MCRYPT_RIJNDAEL_128,                     hash('sha256', $key, true),                     $value,                     MCRYPT_MODE_CBC,                     $iv                 )             );             return $encrypted;         /*             $key = ' wt1U5qZAWJFYUGenFoMOiLwQrGLgdbHA '; //wt1U5MACWJFTXGenFoZoiLwQGrLgdbHA             $result = Security::encrypt($value, $key);