Showing posts with label PHP Functions. Show all posts
Showing posts with label PHP Functions. Show all posts

Tuesday, January 23, 2018

Simple Two way Encryption and Decryption Function PHP



Hello guys, after a long time, I came back to my blog with new flavor of articles, and I am plan to concentrate my blog half my working day here after. So my followers can expect valuable development ideas from me through comment and feed.

Here we go our come back article, Here now I teach you the Two way encryption and decryption method with full explanation.

Objective Build a function for Two Way Encryption and Decryption:

            Encrypt as well as Decrypt our given string with our own Encrypt Decrypt Key and Initiative Vector (IV) (?), with Advanced Encryption Standard (AES) (?) this method is highly secure method all time ever with few PHP functions to build Two way Encryption and Decryption.

Functions Involved in Two Day Encryption and Decryption.

hash - Generate a hash value (message digest)
string hash ( string $algo , string $data [, bool $raw_output = false ] )

substr - Return part of a string
            string substr ( string $string , int $start [, int $length ] )

base64_encode - Encodes data with MIME base64
string base64_encode ( string $data )

base64_decode - Decodes data encoded with MIME base64
            string base64_decode ( string $data [, bool $strict = false ] )

openssl_encrypt - Encrypts data
string openssl_encrypt ( string $data , string $method , string $key [, int $options = 0 [, string $iv = "" [, string &$tag = NULL [, string $aad = "" [, int $tag_length = 16 ]]]]] )

openssl_decrypt - Decrypts data
            string openssl_decrypt ( string $data , string $method , string $key [, int $options = 0 [, string $iv = "" [, string $tag = "" [, string $aad = "" ]]]] ) 

Two Encryption & Decryption Function

/*
Written by: Jailani M, http://www.W3Lessons.com
Defineds:
ED_KEY - Encryption and Decription key your choice
IV_KEY - INITIATIVE VECTOR your choice
*/
define("ED_KEY","your_key");
define("IV_KEY","your_iv");

function w3_encode( $string) {
    $encrypt_method = "AES-256-CBC";
    $key = hash( 'md5', ED_KEY );
    $iv = substr( hash( 'md5', IV_KEY ), 0, 16 );
    $encoded_string = base64_encode( openssl_encrypt( $string, $encrypt_method, $key, 0, $iv ) );
    return $encoded_string;
}

function w3_decode($string)
{
    $encrypt_method = "AES-256-CBC";
    $key = hash( 'md5', ED_KEY );
    $iv = substr( hash( 'md5', IV_KEY ), 0, 16 );
    $decoded_string = openssl_decrypt( base64_decode( $string ), $encrypt_method, $key, 0, $iv );
    return $decoded_string;
}



Download This Script     Live Demo     Download Script

Wednesday, February 18, 2015

Get Google Page through PHP for Multiple URL

Here is the PHP Script for best solution for Finding PR for multiple URLs hope this very useful for your projects.


Google PageRank Script PHP

Tuesday, October 9, 2012

Optimize All MySQL Tables PHP


If you looking for optimizing MySQL database tables from PHP dynamically, here is a solution to optimize entire tables a database.

Optimizing Tables we need to get Entire table list using "SHOW TABLES" query. as this return entire table names as record, after getting executed of this command call OPTIMIZE TABLE and REPAIR TABLE as per the table needs.

Primary Optimization will failed if the table been damage or corrupt. we will apply REPAIR TABLE

<?php

mysql_connect("localhost","root","");
mysql_select_db("your_db_name");


echo "<br /> OPTIMIZING TABLES ";

$alltables = mysql_query("SHOW TABLES");

// Process all tables.
while ($table = mysql_fetch_assoc($alltables))
{
 foreach ($table as $db => $tablename)
 {
 // Optimize them!
 if(mysql_query("OPTIMIZE TABLE ".$tablename))
  echo "<br>OK Optimized : ".$tablename;
 else
 {
  echo "<br>Error Optimizing Applying Reapir... ".$tablename;
  // Apply Reapirt if Optimization Failed;
  if(mysql_query("REPAIR TABLE ".$tablename))
  echo "Repaired !";
  else
  echo "Error Repairing Table!";
 }
 }
}
mysql_close();
?>




Tuesday, August 21, 2012

Alexa Rank Script PHP - Get Alexa Rank in PHP



To Find Alexa Rank in php using following function

PHP Script to get Alexa Rank

<?php

function alexaRank($domain){
    $remote_url = 'http://data.alexa.com/data?cli=10&dat=snbamz&url='.trim($domain);
    $search_for = '<POPULARITY URL';
 $part = NULL;
    if ($handle = @fopen($remote_url, "r")) {
        while (!feof($handle)) {
            $part .= fread($handle, 100);
            $pos = strpos($part, $search_for);
            if ($pos === false)
            continue;
            else
            break;
        }
        $part .= fread($handle, 100);
        fclose($handle);
    }
    $str = explode($search_for, $part);
    $str = @array_shift(explode('" SOURCE="panel"/>', $str[1]));
    $str = explode('TEXT="', $str);

    return $str[1];
}


echo alexaRank("google.co.in");

?>


Saturday, February 25, 2012

Reduce HTTP Request with Data URI in PHP


A part of website optimization technique is Reduce no of HTTP Request when user attempt to open our Web page from our website. HTTP Request count is an important factor for Traffic worthy websites to make your web pages / websites more responsive on time. In this factor of HTTP Request optimization to reduce the HTTP request count of various images in our websites by Rewriting with Data URI Scheme. Data URI is the technology which is used to Reduce and Optimize HTTP request and response.



For example If you have a gallery section in your website. Gallery images are in two Sections one is Thumbnails and another one is actual images. in this case set of 5 Images will request 10 HTTP request every time the Page opens. in this case we can use Data URI with PHP to reduce this HTTP request 0, Data URI will cheat our server and retrieve the image data as plain code along with our standard HTML code.