27 Dec 2016

PDO Based Custom Class & Functions -

PDO Based Custom Class & Functions -

      Link 1 - https://github.com/indieteq/indieteq-php-my-sql-pdo-database-class
   
      Link 2 - http://culttt.com/2012/10/01/roll-your-own-pdo-php-class/

Alternate Link -  https://www.phpclasses.org/package/9209-PHP-Access-databases-using-PDO.html 

26 Dec 2016

Mailchimp Signle Opt In Api Code

Mailchimp Signle Opt In Api Code -

<?php
include_once('mailchimp/MailChimp.class.php');
$mailchimp_api="c562cb098c4170e2136eca81c3e4d9bb-us13";
$MailChimp = new MailChimp($mailchimp_api);


if(isset($_REQUEST['FLAG']) & $_REQUEST['FLAG']=="SEND_SUBSCRIBE")
{

$email = isset($_REQUEST['EMAIL'])?trim($_REQUEST['EMAIL']):'';
$fName = isset($_REQUEST['FNAME'])?trim($_REQUEST['FNAME']):'';
$lName = isset($_REQUEST['LNAME'])?trim($_REQUEST['LNAME']):'';

//print_r($email);
//exit;

if((!isset($email) || $email=='') && !filter_var( $email ,FILTER_VALIDATE_EMAIL)){
echo 'This email address is not valid';
}else{
$result = $MailChimp->call('lists/subscribe', array(
'id'                => '86654347f6',
'email'             => array('email'=>$email),
'merge_vars'        => array('MERGE1'=>$fName, 'MERGE2'=>$lName),
'double_optin'      => false,
'update_existing'   => true,
'replace_interests' => false,
'send_welcome'      => false,
));
  // echo 'success';
if (!empty( $result['leid']) ) {
  header("Location: ".$siteUrl."/newsletter-opt-in-confirmation/");
exit;
}
else
{
header("Location: ".$siteUrl."/newsletter-opt-in/?res=error");
exit;
}
}
}


<?php
/**
 * Super-simple, minimum abstraction MailChimp API v2 wrapper
 *
 * Requires curl (I know, right?)
 * This probably has more comments than code.
 *
 * @author Drew McLellan <drew.mclellan@gmail.com>
 * @version 1.0
 */
class MailChimp
{
private $api_key;
private $api_endpoint = 'https://<dc>.api.mailchimp.com/2.0/';
private $verify_ssl   = false;



/**
* Create a new instance
* @param string $api_key Your MailChimp API key
*/
function __construct($api_key)
{
$this->api_key = $api_key;
list(, $datacentre) = explode('-', $this->api_key);
$this->api_endpoint = str_replace('<dc>', $datacentre, $this->api_endpoint);
}




/**
* Call an API method. Every request needs the API key, so that is added automatically -- you don't need to pass it in.
* @param  string $method The API method to call, e.g. 'lists/list'
* @param  array  $args   An array of arguments to pass to the method. Will be json-encoded for you.
* @return array          Associative array of json decoded API response.
*/
public  function call($method, $args=array())
{
return $this->_raw_request($method, $args);
}




/**
* Performs the underlying HTTP request. Not very exciting
* @param  string $method The API method to be called
* @param  array  $args   Assoc array of parameters to be passed
* @return array          Assoc array of decoded result
*/
private function _raw_request($method, $args=array())
{    
$args['apikey'] = $this->api_key;

$url = $this->api_endpoint.'/'.$method.'.json';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_USERAGENT, 'PHP-MCAPI/2.0');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->verify_ssl);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($args));
$result = curl_exec($ch);
curl_close($ch);

return $result ? json_decode($result, true) : false;
}

}

25 Dec 2016

Google Recaptcha Server side Code

Google Recaptcha Server side Code -

if(isset($_POST['gecaptcha']) && !empty($_POST['gecaptcha']))
    {  
        $captchaurl = "https://www.google.com/recaptcha/api/siteverify";

        // values for verifying recaptha
        $captcha_params = array(
            'secret'   => '6LdUniUTAAAAAEYr3kW0imae59cYzEpN7TFxQnG-',
            'response' => $_POST['gecaptcha'],
            'ip'       => $_SERVER['REMOTE_ADDR']
        );

        $curl_init = curl_init();
        curl_setopt($curl_init, CURLOPT_URL, $captchaurl);
        curl_setopt($curl_init, CURLOPT_RETURNTRANSFER, 1);

        // send recapture values via POST
        curl_setopt($curl_init, CURLOPT_POST, count($captcha_params));
        curl_setopt($curl_init, CURLOPT_POSTFIELDS, $captcha_params);

        curl_setopt($curl_init, CURLOPT_SSL_VERIFYPEER, false);

        $results = curl_exec($curl_init);
        curl_close($curl_init);

        $results = json_decode($results, true);

        if($results['success'])
        {  
            echo 1;
        }
        else
        {
            echo 0;
        }          
    }
    else
    {
        echo 0;
    }

21 Dec 2016

Command Line to import large file in Mysql

Command Line to import large file in Mysql
      mysql -u username -p -h hostname databasename < dump.sql

29 Nov 2016

htaccess rules shortcut definition



.htaccess flag list

  • C (chained with next rule)
  • CO=cookie (set specified cookie)
  • E=var:value (set environment variable var to value)
  • F (forbidden - sends a 403 header to the user)
  • G (gone - no longer exists)
  • H=handler (set handler)
  • L (last - stop processing rules)
Last rule: instructs the server to stop rewriting after the preceding directive is processed.
  • N (next - continue processing rules)
  • NC (case insensitive)
  • NE (do not escape special URL characters in output)
  • NS (ignore this rule if the request is a subrequest)
  • P (proxy - i.e., apache should grab the remote content specified in the substitution section and return it)
  • PT (pass through - use when processing URLs with additional handlers, e.g., mod_alias)
  • R (temporary redirect to new URL)
  • R=301 (permanent redirect to new URL)
  • QSA (append query string from request to substituted URL)
  • S=x (skip next x rules)
  • T=mime-type (force specified mime type)

20 Nov 2016

Rest API Example Link

Rest API Example Link-

1. https://www.leaseweb.com/labs/2015/10/creating-a-simple-rest-api-in-php/

2. https://www.parse.com/questions/upload-an-image-using-rest-api-and-php

3. http://www.techflirt.com/php/php-curl/curl-examples.html

10 Sept 2016

Fiddle for map with city dropdown implementation

Fiddle for map with city dropdown implementation -

http://www.outsharked.com/imagemapster/examples/usa.html

26 Aug 2016

Java script function for cookie based Implementation

Java script function for cookie based Implementation

 var list = new cookieList("MyItems");
list.clear();
/console.log(list.items());
list.remove(advid.toString());
 if(!list.contain(advid)){
 list.add(advid);
 }

//This is not production quality, its just demo code.
var cookieList = function(cookieName) {
//When the cookie is saved the items will be a comma seperated string
//So we will split the cookie by comma to get the original array
var cookie = $.cookie(cookieName);
//Load the items or a new array if null.
var items = cookie ? cookie.split(/,/) : new Array();

//Return a object that we can use to access the array.
//while hiding direct access to the declared items array
//this is called closures see http://www.jibbering.com/faq/faq_notes/closures.html
return {
    "add": function(val) {
        //Add to the items.
        items.push(val);
        //Save the items to a cookie.
        //EDIT: Modified from linked answer by Nick see
        //      http://stackoverflow.com/questions/3387251/how-to-store-array-in-jquery-cookie
        $.cookie(cookieName, items.join(','));
    },
    /*"remove": function (val) {
        //EDIT: Thx to Assef and luke for remove.
        indx = items.indexOf(val);
        if(indx!=-1) items.splice(indx, 1);
        $.cookie(cookieName, items.join(','));        },*/
"contain": function (val) {
//Check if an item is there.
//alert("Hello");
var index='';
if(index = items.indexOf(val.toString())){
console.log("Found index of Ad is="+index);
}
if(index>-1){
return true;
}else{
return false;
}
},
"remove": function (val) {
//EDIT: Thx to Assef and luke for remove.
/** indexOf not support in IE, and I add the below code **/
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function(obj, start) {
for (var i = (start || 0), j = this.length; i < j; i++) {
if (this[i] === obj) { return i; }
}
return -1;
}
}
var indx = items.indexOf(val);
if(indx!=-1) items.splice(indx, 1);
//if(indx!=-1) alert('lol');
$.cookie(cookieName, items.join(','));
},
    "clear": function() {
        items = null;
        //clear the cookie.
        $.cookie(cookieName, null);
    },
    "items": function() {
        //Get all the items.
        return items;
    }
  }
}

12 Aug 2016

Php 5 Example - ​http://www.phpclasses.org/package/3698-PHP-MySQL-database-access-wrapper.html

Php 5 Example -
​http://www.phpclasses.org/package/3698-PHP-MySQL-database-access-wrapper.html

Isotopes  Example Link  -

http://www.9bitstudios.com/2013/04/jquery-isotope-tutorial/

http://www.9bitstudios.com/demos/blog/jquery-isotope/

2 Aug 2016

Best Datepicker Plugin

Best datepicker plugin download link -   https://github.com/t1m0n/air-datepicker

Second One -  http://keith-wood.name/datepick.html

Third &best one - http://xdsoft.net/jqplugins/datetimepicker/


<code>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<link rel="stylesheet" type="text/css" href="jquery.datetimepicker.css"/>
<style type="text/css">

.custom-date-style {
background-color: red !important;
}

.input{
}
.input-wide{
width: 500px;
}

</style>
</head>
<body>

<h3>DatePicker</h3>
<input type="text" id="datetimepicker2" value="<?php echo date('d/m/Y', strtotime('24-07-2012')); ?>" /><br><br>


<script src="jquery.js"></script>
<script src="jquery.datetimepicker.full.js"></script>

<script type="text/javascript">
//$.datetimepicker.setLocale('en');
$('#datetimepicker2').datetimepicker({
//yearOffset:222,
lang:'en',
timepicker:false,
format:'d/m/Y',
formatDate:'Y/m/d',
minDate:'1950/01/02', // yesterday is minimum date
maxDate:'2050/01/02' // and tommorow is maximum date calendar
});
</script>
</body>
</html>
</code>

29 Jul 2016

Select Dropdown to another select box & arrow to add remove options

Select Dropdown to another select box & arrow to add remove options -

http://www.voidcanvas.com/demo/?art=http://voidcanvas.com/move-option-from-one-select-box-to-another-and-vice-versa&demoid=7511pair-select#.V5s8d_l96Uk

SQL Best Practices Website

SQL Best Practices Website -
http://docs.sqlalchemy.org/en/latest/core/constraints.html

17 Jul 2016

MP4 Convertor Software Download Link -

MP4 Convertor Software Download Link -
                 https://handbrake.fr/downloads.php

6 Jul 2016

Ajax File Upload Script

Ajax File Upload Script -
Link-  https://www.formget.com/ajax-image-upload-php/

30 Jun 2016

Link to see validation rules for forms

Link to see validation rules-

http://www.javascript-coder.com/form-validation/jquery-form-validation-guide.phtml

7 Jun 2016

Learn Github

Learn Github -
http://tutorialzine.com/2016/06/learn-git-in-30-minutes/