Code Monkey home page Code Monkey logo

hashids-module-for-codeigniter-hmvc's Introduction

Hashids-Module-For-codeigniter-HMVC

Hashids module for codeigniter HMVC

Hashids is a small open-source library that generates short, unique, non-sequential ids from numbers. It converts numbers like 347 into strings like “yr8”, or array of numbers like [27, 986] into “3kTMd”. You can also decode those ids back.

modules

  |_Hashids
 	  |_config
 	      |_encrypt.php // $config['salt']='setEncryptionDecryptionString';
 	  |
      |_controller
          |_Hashids.php

third_party

|_hashids
    |_lib
    |_Vendore
    |_composer.json

Third party folder contain all dependancies which required for hashids

Hashids Controller :

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

require_once APPPATH."/third_party/hashids/vendor/autoload.php"; 

class Hashids extends Controller 
{

	private $hashids='';
	function __construct(){
	
	    parent::__construct();
   	    $this->config->load('hashids/encrypt', TRUE);
      	    $config_encrypt=$this->config->item('encrypt');
      	    $this->hashids = new Hashids\Hashids($config_encrypt['salt']);
	    
	}
 	public function encrypt($plainText)
 	{
	 	return $this->hashids->encode($plainText);
 	}
 	public function decrypt($cipherText,$single_flag=TRUE)
 	{
 		if($single_flag == TRUE)
 		{
 			$single_decrypt = $this->hashids->decode($cipherText);
 			return $single_decrypt[0];
 		}
 		else
 		{
 			return $this->hashids->decode($cipherText);;
 		}
 	}

}

Example :-

class Site extends Controller
{

	function __construct()
	{
		parent::Controller();
		$this->load->module('hashids'); // load module
	}
	
	function members_area()
	{
		modules::run('login/is_logged_in');
		$user_id=2;
		$data['id']=$user_id; // Normal Id 
		$encrypt_id = $this->hashids->encrypt($user_id); 
		// encrypt() function from hashid module will convert normal id into encrypted Id
		
		$data['encrypt_id']=$encrypt_id; // encrypted Id
		
		$decrypt_id = $this->hashids->decrypt($encrypt_id); 
		// decrypt() function will convert encrypted id back to normal id 
		
		$data['decrypt_id']=$decrypt_id; // Normal Id
		$this->load->view('logged_in_area',$data);
	}
}

Note :- Controller is name of Base controller

Thanks to :- Ivan Akimov

hashids-module-for-codeigniter-hmvc's People

Contributors

neonblack007 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.