Skip to main content

Posts

Showing posts from 2017

Currency Converter with php using Google Api

Currency Converter with php using Google Api Google provides google finance api to convert currency . here is the simple example of currency conversion using google finance API. <?php $from_currency = "USD"; $to_currency = "INR"; $amount = "100.000"; $converted_currency=convertCurrency($from_currency, $to_currency, $amount); echo $converted_currency;  function convertCurrency($from, $to, $amount){     $from = urlencode($from);     $to = urlencode($to);     $data = file_get_contents("https://finance.google.com/finance/converter?a=$amount&from=$from&to=$to");     preg_match("/<span class=bld>(.*)<\/span>/",$data, $converted);     $converted = preg_replace("/[^0-9.]/", "", $converted[1]);     return number_format(round($converted, 3),2); } ?>

Cakephp 3x Send Email with Cronjob

Cakephp 3.x - Send Email with Cronjob Easily Set Cron job with cakephp 3.x A Cron job is a task that is run based on time interval , we just need to set cron job from our cpanel and it will run automatically backend side . We can run cron job every minute , every hour, every day or every month based on our requirement. In cakephp 3.x to set a cron job please follow the below simple steps First we need to create a php file on webroot so we can run our controller action as php file in cronjob Create a file cron.php in webroot folder (location - YourProject/webroot/cron.php) and paste the following code Cron.php <?php $_SERVER[ 'HTTP_HOST' ] = 'yourdomain.com'; //  use only domain name here require dirname(__DIR__) . '/config/bootstrap.php'; use Cake\Network\Request; use Cake\Network\Response; use Cake\Routing\Router; use Cake\Routing\DispatcherFactory; if(PHP_SAPI == "cli" && $argc == 2) {     $dispatcher = DispatcherFacto

LARAVEL 5x CHECK STATUS ACTIVE BEFORE LOGIN

LARAVEL 5x CHECK STATUS ACTIVE BEFORE LOGIN For this tutorial we are using laravel 5.4 and we will add validation to user login that if user status is active then user can login otherwise if user status is not active then show error to user. so follow the below steps. The best way to add status validation is through a middleware to check status . so we are creating middleware and we will use it in loginController. Run the following command in console or cmd to create checkStatus middleware .   php artisan make:middleware CheckStatus after completion of command " Middleware created successfully " will show. then paste the below code into file . <?php namespace App\Http\Middleware; use Closure; use Illuminate\Support\Facades\Auth; class CheckStatus {     /**      * Handle an incoming request.      *      * @param  \Illuminate\Http\Request  $request      * @param  \Closure  $next      * @return mixed      */     public function handle($request,

Cakephp 3x- Add Email verification on registration

How to add email verification on registration Cakephp 3.x In this tutorial we will add email verification on user register so whenever a new user registered in our site then he will receive an email with confirmation link and after confirmation link click , his account will activate. this tutorial is also for that users that want to learn how to setup email configration in cakephp 3.x. for basic knowledge you can check this post Send mail using mail class in cakephp 3 SO FOLLOW THESE SIMPLE STEPS TO VERIFY USER EMAIL ON REGISTRATION First we need to add one table with three columns id email and status . you can run below query to create a table CREATE TABLE `cake`.`users` ( `id` INT NOT NULL AUTO_INCREMENT , `email` VARCHAR(50) NOT NULL , `otp` VARCHAR(50) NOT NULL , `status` INT NOT NULL DEFAULT '0' , PRIMARY KEY (`id`)) ENGINE = InnoDB; Your database table should look like In this tutorial we will use gmail for smtp so first we need to configure EmailTra

Cakephp 3x Add TinyMCE text editor in 2 Steps

Cakephp 3.x Add text editor in 2 Steps In this tutorial we will use TinyMCE because its easy to implement TinyMCE text editor Step 1 So First Add this js to your header or default layout or your preferred location where you call other js files <script src="//cdn.tinymce.com/4/tinymce.min.js"></script>   <script> tinymce.init({ selector:'.edittextarea', height: 500,  plugins: [     'advlist autolink lists link print preview anchor',     'visualblocks code fullscreen',     'insertdatetime table contextmenu paste code'   ], }); </script>   Step 2 Now Add edittextarea class to textarea where you want to change textarea to text editor Here is the example of how to create text editor textarea in Cakephp 3.x  <?= $this->Form->input('description', array('type' => 'textarea','class' => 'edittextarea form-control','value'=>$description,

Cakephp-3x-On debug Mode for controller or action

Cakephp 3.x On debug Mode for a specific controller or action To on debug mode for only one controller or action you should follow below steps:- First call configure into your controller at the top(check its already called then don't call it again) use Cake\Core\Configure; Then in your controller action paste this line or if you want it to on for all actions of a controller then paste this line into beforeFilter or initialize Configure::write('debug', 2);    Now run your controller action and your debug mode will be on for specific controller and action. On Debug mode only for specific IP Address If you want to on debug only for you or any specific IP Address then first get your ip address you can get ip address in cakephp using this code. use Cake\Network\Request; echo $this->request->clientIp(); OR with php $_SERVER['REMOTE_ADDR']; then you can use below code         $clientIpAddress = $this->request->clientIp();    

PHP check a string contains specific value or string

How to check if a string having specific characters or string In PHP we can check with strpos() . strpos() is the simplest way to get string having search texts or not. Examples :- For examle here is a php string and we want to know that it contains "php" word or not. $a = 'Hello string do u have php word?'; The below line of code echo true if php word exist in string. if (strpos($a, 'php') !== false) { echo 'true'; } OR if (strpos($string, $word) === FALSE) { ... not found ... } Answer 2 We can also use preg_match() to determine that Example if (preg_match('/php/',$a)) {   echo 'true'; }

Install Cakephp with Composer on Linux

How to Install Cakephp with Composer on Linux System Here is the complete tutorial for how to install cakephp letest version with composer on linux system. If you dont have install composer then first you should install composer To install composer run the following commands one by one- php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" php -r "if (hash_file('SHA384', 'composer-setup.php') === '55d6ead61b29c7bdee5cccfb50076874187bd9f21f65d8991d46ec5cc90518f447387fb9f76ebae1fbbacf329e583e30') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" php composer-setup.php php -r "unlink('composer-setup.php');" OR you can install composer with curl by using this command curl -sS https://getcomposer.org/installer | php these commands will download the latest composer.phar in the current directory