Sunday, 19 May 2019

jwt in wordpress

Jwt authentication in wordpress for rest api,

In this tutorial we will learn how we can implement jwt authentication in wordpress for every Rest api request (Not only for private posts.).

Using jwt authentication we can protect your wordpress data post data.

Step: 1. Install and activate the wp rest api plugin. And download the jwt library form github link is given below.


Place this file inside your active theme directory along with functions.php file

comment these few lines as show below:

//namespace Firebase\JWT;
//use \DomainException;
//use \InvalidArgumentException;
//use \UnexpectedValueException;
//use \DateTime;

and save this file with "jwt.php".
Than include this file in function.php using this line of code

require get_template_directory() . '/jwt.php'; 

Step 3: create a page template token.php

as show below:
get jwt token

Hello is the secret key at line no 13.
at line number 6 you can change username or password as you desire.

Step: 4 Put this code inside function.php

decode jwt token data

Get token form headers and decoded the token data using jwt libraray.

Postman testing sample images are given below:


get jwt token passing username and password

Send jwt token with every request to get data:
send jwt token in header data


Thank you for giving yours time.

Saturday, 13 April 2019

create pdf file from caldera form data

Caldera form pdf file

Install Run Action addon  then add a action on process

as shown in fig:
caldera form pdf  

Install dompdf (open source) which using composer inside you theme folder 
Using this command

Composer require dompdf

Than add the following code to yours functions.php file

require_once '/vendor/autoload.php';
 use Dompdf\Dompdf;
add_action('create_pdf','create_pdf_fun');

function create_pdf_fun($data)
{

$html = 'First Name:'.$data['first_name'].'<br>
        Last Name:'.$data['last_name'].'<br>
        Email:'.$data['email_address'].'<br>
        message:'.$data['message'].'<br>
        Question:'.$data['comments_questions'];
// instantiate and use the dompdf class
$dompdf = new Dompdf();
$dompdf->loadHtml($html);

$dompdf->setPaper('A4', 'landscape');
$dompdf->render();

$output = $dompdf->output();

$subdir = wp_get_upload_dir();
$upload_path = 'wp-content/uploads'.$subdir['subdir'].'/'.rand(1,2000).'test.pdf';
file_put_contents($upload_path, $output);
}

Thank you for giving your time!
 

Saturday, 16 March 2019

send caldera form data to api

Send caldera form data to api

How to send a HTTP POST with the form data to another URL

  • Install caldera form run action add on which is free

    Then add post processor as shown in figure 

    Define action name e.g. send_data

    and put this code in function.php as given below


    add_action('send_data','send_data_function');

    function send_data_function($data)
    {

    $url = 'http://localhost/api.php';
    $myvars = array('firstname' =>$data['first_name'], //$data['slug'] change according to your form field slug
                    'lastname' => $data['last_name'],                  'email' => $data['email_address'],
                    'message' => $data['message'],
                    'commentque' => $data['comments_questions']
     );

    $ch = curl_init( $url );
    curl_setopt( $ch, CURLOPT_POST, 1);
    curl_setopt( $ch, CURLOPT_POSTFIELDS, $myvars);
    curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt( $ch, CURLOPT_HEADER, 0);
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);

    curl_exec( $ch );

    }

    In this way we can post the caldera form data  to api in wordpress

 

Saturday, 26 January 2019

Self attested declaration for no family member in Government Job pdf

Self attested declaration for no family member in Government Job pdf

Download pdf Hssc Self-attested declaration for no family member in Government Job

Take print on A-4 size sheet then fill the all particulars

Thanks for visiting.....

Click the below button to
Self-attested declaration for no family member in Government Job

Sunday, 6 January 2019

htet tgt paper downlaod 2019 pdf

Htet previous year tgt paper download.

This paper was held in 05-Jan-2019.

Thanks for visiting.....

Click the below button to download paper.

Thursday, 8 November 2018

Jwt in php codeigniter framework

Jwt in php Codeigniter framework, My internet connection is  Airtel

Follow the steps as shown in given video

 



In controller Test.php


<?php
require APPPATH . '/libraries/ImplementJwt.php';

class Test extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->objOfJwt = new ImplementJwt();
        header('Content-Type: application/json');
    }

    /////////// Generating Token and put user data into  token ///////////

    public function LoginToken()
    {
            $tokenData['uniqueId'] = '55555';
            $tokenData['role'] = 'admin';
            $tokenData['timeStamp'] = Date('Y-m-d h:i:s');
            $jwtToken = $this->objOfJwt->GenerateToken($tokenData);
            echo json_encode(array('Token'=>$jwtToken));
         }
    
    //////// get data from token ////////////
        
    public function GetTokenData()
    {
    $received_Token = $this->input->request_headers('Authorization');
        try
            {
            $jwtData = $this->objOfJwt->DecodeToken($received_Token['Token']);
            echo json_encode($jwtData);
            }
            catch (Exception $e)
            {
            http_response_code('401');
            echo json_encode(array( "status" => false, "message" => $e->getMessage()));exit;
            }
    }
}

 

Step 2: ImplementJwt.php

 <?php
require APPPATH . '/libraries/JWT.php';


class ImplementJwt
{
  

    //////////The function generate token/////////////
    PRIVATE $key = "subcribe_my_channel"; // url: https://www.youtube.com/watch?v=zD4IGp1lBWs
    public function GenerateToken($data)
    {         
        $jwt = JWT::encode($data, $this->key);
        return $jwt;
    }
   


   //////This function decode the token////////////////////
    public function DecodeToken($token)
    {         
        $decoded = JWT::decode($token, $this->key, array('HS256'));
        $decodedData = (array) $decoded;
        return $decodedData;
    }
}
?> 

Download  jwt library: 


https://github.com/firebase/php-jwt

To check jwt token data:


https://jwt.io/

 

 

Friday, 25 May 2018

paytm gateway integration in codeigniter

paytm gateway integration in codeigniter

How we can integrate paytm gateway in codeigniter framework

Step 1: Downlaod the paytm gateway library form the github

https://github.com/Paytm-Payments/Paytm_Web_Sample_Kit_PHP

You can follow this video for placing paytm lib files in codeigniter framework



In controller

<?php

require_once(APPPATH."libraries/lib/config_paytm.php");
require_once(APPPATH."libraries/lib/encdec_paytm.php");


class Welcome extends CI_Controller {

    public function PaytmGateway()
    {
        $orderId = 106; /// must be unique
      $this->StartPayment($orderId);
    }

    public function StartPayment($orderId)
    {
        $paramList["MID"] = PAYTM_MERCHANT_MID;
        $paramList["ORDER_ID"] = $orderId;     
        $paramList["CUST_ID"] = 344;   /// according to your logic
        $paramList["INDUSTRY_TYPE_ID"] = 'RETIAL';
        $paramList["CHANNEL_ID"] = 'WEB';
        $paramList["TXN_AMOUNT"] = 50;
        $paramList["WEBSITE"] = PAYTM_MERCHANT_WEBSITE;
   
        $paramList["CALLBACK_URL"] = "http://127.0.0.1/gateway/Welcome/PaytmResponse";
        $paramList["MSISDN"] = '77777777'; //Mobile number of customer
        $paramList["EMAIL"] ='foo@gmail.com';
        $paramList["VERIFIED_BY"] = "EMAIL"; //
        $paramList["IS_USER_VERIFIED"] = "YES"; //
      //  print_r($paramList);
        $checkSum = getChecksumFromArray($paramList,PAYTM_MERCHANT_KEY);

        ?>

        <!--submit form to payment gateway OR in api environment you can pass this form data-->
   
        <form id="myForm" action="<?php echo PAYTM_TXN_URL ?>" method="post">
        <?php
         foreach ($paramList as $a => $b) {
        echo '<input type="hidden" name="'.htmlentities($a).'" value="'.htmlentities($b).'">';
       }
       ?>
            <input type="hidden" name="CHECKSUMHASH" value="<?php echo $checkSum ?>">
        </form>
        <script type="text/javascript">
            document.getElementById('myForm').submit();
         </script>
 
<?php
    }

    /////////// response from paytm gateway////////////
    public function PaytmResponse()
    {
        $paytmChecksum = "";
        $paramList = array();
        $isValidChecksum = "FALSE";

        $paramList = $_POST;
        echo "<pre>";
        print_r($paramList);
   
//        $paytmChecksum = isset($_POST["CHECKSUMHASH"]) ? $_POST["CHECKSUMHASH"] : ""; //Sent by Paytm pg
//
//        $isValidChecksum = verifychecksum_e($paramList, PAYTM_MERCHANT_KEY, $paytmChecksum); //will return TRUE or FALSE string.
//
//        if($isValidChecksum == "TRUE")
//        {
//            if ($_POST["STATUS"] == "TXN_SUCCESS")
//            { /// put your to save into the database // tansaction successfull
//                var_dump($paramList);
//            }
//            else {/// failed
//                var_dump($paramList);
//            }
//        }else
//        {//////////////suspicious
//           // put your code here
//       
//        }
    }
}
?>

Do not forget to subscribe my channel if this code help you

Thursday, 19 April 2018

PHP codeigniter status code in not working

While making project in Codeigniter framework many developers face these problems:
  • php http_response_code not working 
  • Http response code always returns 200
  • php http_response_code not working when hosting a linux server
  • 404 page not found in not working
  • php 500 not working in codeigniter
  • header already sent error in php
  • warning cannot modify header information headers already sent by (output started xyz.php line no...

All these problems occur when you host your website at Linux server that you have developed in codeigniter framework. 

You have to modify index.php file which is in the root directory of Codeigniter framework.

Step 1) Add ob_start(); function at the beginning of index.php after <?php

This function will turn on the output buffering. so that http response code works correctly. 

Step 2) define('ENVIRONMENT','development');

The modified index.php file is as


Thanks for sharing your valuable time.......

Sunday, 4 March 2018

json validation in codeigniter

json validation in codeigniter

How to validate json data or json nested array in codeigniter


For example we have two fields email and password to validate and sending request from postman as shown below:
request method: post
{
    "email":"sachinsharma.one@gmail.com",
    "password":"12345"
}

In controller

public function login_post()
{
header('Content-type: application/json');

                $request = json_decode(file_get_contents('php://input'),true);

$this->form_validation->set_data($request); /// for setting data

$this->form_validation->set_rules('email','Email', 'required|valid_email');
$this->form_validation->set_rules('password','PASSWORD', 'required|min_length[4]|max_length[20]');

if($this->form_validation->run()==false)
{
echo validation_errors();
}
else
{
// your code..............
}
}

In this way you can validate json data or even big json data

Tuesday, 12 September 2017

Htet computer science 2017

Hi friends we are always ready to provide you job alerts of Govt as well as private. we provide you study material, question bank of computer and question papers of various competitive exams.

Questions asked in Htet computer science  PGT Level-3

Q.1…………….. symbol is used to see every column of a table?
a) /     
b) _ _
c) *
d) !


Q. 2 HTTP  is a combination of FTP  and ………..  .
a) SMTP
b) E-mail
c) Web page
d) Web browser


Q. 3 What is the output of the following C++ program ?
#include <iostream.h>
Int x=7;
Void showx();
Void showagain();
Void main()
{
                Showx();
                Showx();
                Showxagain();
}
Void showx()
{
Int x= 34;
Cout<<x++<<endl;

}
Void showagain()
{
Cout<<x++<<endl;
}
Options are:
a)  35
      36
      37
b)   34
      34
      7
c) 35
     36
     8
d) 35
    35
    8


Q 4. The …………………… attribute specifies the URL of the document that you want to link.
a) img
b) a
c) src
d) href


Q 5. Which file keeps command to execute automatically when operating system is started ?
a) command.com
b) autoexec.bat 
c) config.sys
d) all options are wrong


NEXT PAGE 2, PAGE 3, PAGE 4, PAGE 5