Thursday 1 December 2016

login with facebook with php example

login with facebook with php example

//login with facebook with php example
<script
  src="https://code.jquery.com/jquery-1.12.4.min.js"
  integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ="
  crossorigin="anonymous"></script>
<script type="application/javascript">

 

  window.fbAsyncInit = function() {
  FB.init({
    appId      : 'your facebook app id',
    cookie     : true,  // enable cookies to allow the server to access
                        // the session
    xfbml      : true,  // parse social plugins on this page
    version    : 'v2.8' // use graph api version 2.8
  });

  };
 

  // Load the SDK asynchronously
  (function(d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) return;
    js = d.createElement(s); js.id = id;
    js.src = "//connect.facebook.net/en_US/sdk.js";
    fjs.parentNode.insertBefore(js, fjs);
  }(document, 'script', 'facebook-jssdk'));
 
 
  // Pass function you want to login ur sing up;

  function checkLoginState(login) {
 
 
 

 
 
FB.login(function(response) {
    if (response.authResponse) {
   
  FB.api('/me?fields=id,name,email,permissions', function(response) {
                
var facebook_email  = response.email;
var facebook_name = response.name;
var get_role_id = 2;
var facebook_login = 1;
  var google_login = 0;
if(login == "login"){
  $.ajax({
url:"common/facebook_login",
method:"POST",
data:{facebook_email:facebook_email,facebook_login:facebook_login,google_login:google_login},
success: function(res){
if(jQuery.trim(res)=="Your are successfully login"){
//jQuery('.all_error_here').text(res);
//$("#errorDialog").modal('show');
location.reload();
}else{
jQuery('.all_error_here').text(res);
$("#errorDialog").modal('show');
}
//location.reload();
}
});
}else{
  $.ajax({
url:"common/facebook_signup",
method:"POST",
data:{facebook_email:facebook_email,facebook_name:facebook_name,get_role_id:get_role_id,facebook_login:facebook_login,google_login:google_login},
success: function(res){
/*if(jQuery.trim(res)=="sucess"){
jQuery('.all_error_here').text('Thank you for sign up');
$("#errorDialog").modal('show');
}else{
jQuery('.all_error_here').text(res);
$("#errorDialog").modal('show');
}*/
location.reload();
}
});
}
               });
    } else {
     console.log('User cancelled login or did not fully authorize.');
    }
}, { auth_type: 'reauthenticate' });
 
  }
 
 

</script>

<button data-dismiss="modal" data-toggle="modal" onclick="checkLoginState('login')" class="btn btn-block radius-6 facebook-btn"><i class="fa fa-facebook"></i> Sign in with Facebook</button>


//login with facebook with php example

Sunday 27 November 2016

Get geo location using javascript in destop and leptop or computer


Get geo location using javascript in destop and leptop or computer



 <p>Click the button to get your coordinates.</p>

<button onclick="getLocation()">Try It</button>

<p id="demo"></p>

<script>
var x = document.getElementById("demo");

function getLocation() {
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(getAddress);
    } else {
        x.innerHTML = "Geolocation is not supported by this browser.";}
    }
function getAddress(position){

  var lat = position.coords.latitude;
  var lon = position.coords.longitude;

  //grab address via Google API using your position
  var apiurl = 'http://maps.googleapis.com/maps/api/geocode/json?latlng='+lat+','+lon+'&sensor=true';


  //make the Ajax request
  var xhr = new XMLHttpRequest();

  xhr.open("GET", apiurl);
  xhr.onload = function() {
  var result = JSON.parse(xhr.responseText)

    //if we make a successful request and it returns an address
  if(this.status==200){
  //get formatted address from https://developers.google.com/maps/documentation/geocoding/#ReverseGeocoding
  //var result = JSON.parse(xhr.responseText).contents.results[0].formatted_address;
  console.log(result.results[0]['formatted_address']);
alert(result.results[0]['formatted_address']);
      } else {
      //send some general error
     
      }

  }

  xhr.send();
               
}
</script>

Get geo location using javascript in destop and leptop or computer

Tuesday 15 November 2016

jquery replace all single or double quotes

hello Here simple example of replace single and doble quotes using jquery replace function.

we can use jquery replace function to replace single and double quotes.

example below

jquery replace all single or double quotes

we can pass two parameter to replace single quotes in string

//replace all single quotes
var myStr = myStr.replace(/'/g, '');

//replace all double quotes
var myStr = myStr.replace(/"/g, '');

//or abit of fun, replace single quotes with double quotes
var myStr = myStr.replace(/'/g, '"');

//or vice versa, replace double quotes with single quotes
var myStr = myStr.replace(/"/g, ''');

jquery replace all single or double quotes

php and curl get put post delete example

php and  curl get put post delete example

hello here how to pass value in post and put curl in php. 
see the below example.

/*  PUT CURL EXAMPLE (php and  curl get put post delete example) */

$data = array('email'=>'test@test.com','password'=>'test');
$data_json = json_encode($data);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Content-Length: ' . strlen($data_json)));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response  = curl_exec($ch);
curl_close($ch);
echo "<pre>";
print_r($response);


/*  POST CURL EXAMPLE  (php and  curl get put post delete example)*/


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response  = curl_exec($ch);
curl_close($ch);
echo "<pre>";
print_r($response);

/*  GET CURL EXAMPLE  (php and  curl get put post delete example)*/

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
echo "<pre>";
print_r($response);

/*DELETE CURL EXAMPLE  (php and  curl get put post delete example)*/

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response  = curl_exec($ch);
curl_close($ch);
echo "<pre>";
print_r($response);

Tuesday 4 October 2016

convert column name into lowercase in mysql and php

Helllo

convert column name into lowercase in mysql and php

some time we want all table column name in lower case then we can change to manually but here
example you can paste this query after run query. you can change you column name in to lower case


convert column name into lowercase in mysql and php example start.

<?php
$c1 = mysql_connect("localhost","root","");// Connection




$db1 = mysql_select_db("INFORMATION_SCHEMA");



$get_column = mysql_query("SELECT * FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `TABLE_SCHEMA`='data_base_name' AND `TABLE_NAME`='table_name'");

while($row = mysql_fetch_assoc($get_column)){


$old_name = $row['COLUMN_NAME'];
$new_name = strtolower($row['COLUMN_NAME']);
$datatype= $row['DATA_TYPE'];
$size = $row['CHARACTER_MAXIMUM_LENGTH'];



if($row['DATA_TYPE'] !="varchar" && $row['DATA_TYPE'] !="text"){
$query =  "ALTER TABLE mstusers CHANGE $old_name $new_name $datatype".";<br/>";
}else{

$query =  "ALTER TABLE mstusers CHANGE $old_name $new_name $datatype ($size)".";<br/>";
}
echo $query;


}

// Query paste in your  phpmyadmin



?>

Please setup below code replace table_name with you table name and database_name replace with you
database name. also setup up your database connection.

After check all query for convert column name into lowercase in mysql and php.

i think it work for you.

convert column name into lowercase in mysql and php

Monday 3 October 2016

ajax image upload with form data in jquery and php

ajax image upload with form data in jquery and php


Hello Here example how to image upload using ajax using php.

and also know how to another value in ajax request.

ajax image upload with form data in jquery and php. please check below example to pass ajax data pass in jquery.

ajax image upload with form data in jquery and php

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script type="application/javascript">
$(document).ready(function (e) {
    $('#imageUploadForm').on('submit',(function(e) {
        e.preventDefault();

        var formData = new FormData();
var text = $('input[type=text]').val();

formData.append('image', $('input[type=file]')[0].files[0]);
formData.append('test', text);


        $.ajax({
            type:'POST',
            url: $(this).attr('action'),
            data:formData,
            cache:false,
            contentType: false,
            processData: false,
            success:function(data){
                console.log("success");
                console.log(data);
$('#imageUploadForm')[0].reset();
            },
            error: function(data){
                console.log("error");
                console.log(data);
            }
        });
    }));

    $("#ImageBrowse").on("change", function() {
        $("#imageUploadForm").submit();
    });
});
</script>
<form name="photo" id="imageUploadForm" enctype="multipart/form-data" action="<?php echo $_SERVER["PHP_SELF"];?>" method="post">
    <input type="file" id="ImageBrowse"  name="image" size="30"/>
     <input type="text" id="text"  value="nice man" name="text" size="30"/>
    <input type="submit" name="upload" value="Upload" />
   
</form>
<?php
if(isset($_FILES['image'])){
if(!is_dir('ajax_image')){
mkdir('ajax_image');
}
echo "GET TEXT BOX VALUE = ".$_POST['test'];
$path = $_FILES['image']['tmp_name'];
$new = "ajax_image/".uniqid().$_FILES['image']['name'];
move_uploaded_file($path,$new);
}
 ?>

ajax image upload with form data in jquery and php

Saturday 17 September 2016

JQuery Autocomplete example in Codeingniter

JQuery Autocomplete example in Codeingniter

Hello here simple example to autocomplete setup in codegniter

sample code to use it.

 <input type="text"  class="form-control skills"  name="name" placeholder="Type Name"  />
 <style>
.fixedHeight {
   
    font-size:10px;
    max-height: 150px;
    margin-bottom: 10px;
    overflow-x: auto;
    overflow-y: auto;
}


</style>
 <script type="application/javascript">

 $(function() {
$( ".skills" ).autocomplete({
source: '<?php echo base_url() ?>'+'/controler_name/function_name',
   
})
  

$( ".skills" ).autocomplete("widget").addClass("fixedHeight");
});

 </script>

 <?php
 //in controller
 // function name(create you own function name and setup)
 public function userautocompltedservices(){
$term =  $this->input->get('term',true);



$query = $this->db->select('servicename')->from('serviceslist')
       ->where("servicename LIKE '%$term%'")->get();
  
   $datas = $query->result_array();
  foreach($datas as $dat){
 
  $data[] = $dat['servicename'];
}
 
  
   echo json_encode($data);
}

 ?>

 JQuery Autocomplete example in Codeingniter fully example

 

send email using SMTP config in codeigniter 3

Hello

send email using SMTP config in codeigniter 3

here example how to setup SMTP in codeigniter 3

first download the php mailler

put after extract foleder phpmailer folder move to codeigniter in application\libraries

after create libraries in  application\libraries create file my_phpmailer.php

here the code of my_phpmailer.php file

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

class My_PHPMailer {
    public function My_PHPMailer() {
        require_once('PHPMailer/PHPMailerAutoload.php');
    }
   
   


}

3) Go To application\helpers create file  sendemails_helper.php

her code of header 


if(!function_exists('send_emails'))
    {
             function send_emails($emails,$body,$subject){
                    $mail = new PHPMailer;
                   
                    $mail->isSMTP();      
                    $mail->Host = 'smtp.mail.yahoo.com';  //                               // Set mailer to use SMTP
                   
                    $mail->SMTPAuth = true;                               // Enable SMTP authentication
                    $mail->Username = 'yahoomail';                 // SMTP username
                    $mail->Password = 'yahoopassword';                           // SMTP password
                    $mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
                    $mail->Port = 465;                                    // TCP port to connect to
                   
                    $mail->setFrom('jhparmar87@yahoo.com', 'title name');
                   
                   
                    $mail->addAddress($emails, 'user');
               
                   
                    $mail->isHTML(true);                                  // Set email format to HTML
                   
                    $mail->Subject = $subject;
                    $mail->MsgHTML($body);
                   
                    $mail->send();
           
             }
    }

after go to application\config open the file autoload.php

$autoload['libraries'] = array('database','session','My_PHPMailer');// here add you library My_PHPMailer

$autoload['helper'] = array('url', 'file','form','sendemails');// here add you helper file  sendemails

after when controler you want to send mail from smtp setup this helper function

    send_emails("test@yahoo.com","body content","subject"); 

here fully exmple of send email using SMTP config in codeigniter 3 please check it now

Friday 16 September 2016

How to fetch title of an product name from a database and send it to the header template in CodeIgniter

How to fetch title of an product name from a database and send it to the header template in CodeIgniter

Hello

If you want product name title in header title then follow this in incrustation.

In Model

function get_prductname($pid)
{
    $query = $this->db->query("SELECT * FROM table_name WHERE pid= '$pid' ");
   
    $count = count($result); # New

    return  $result = $query->row();
}
 
In Controller
 
public function prodcudetail($pid)
{
    $result = $this->Listing_model->get_prductname($pid); # Changed

    $data["page_title"] = $result[0]['field_name']; # Changed

        $this->load->view('includes/header',$data); # Changed
        $this->load->view('listings/listing_card',$data);
        $this->load->view('includes/footer');

}  
 
In View
 
php echo (!empty($page_title->productname)) ? $page_title->productname : ''; ?> # Changed   
 
This example of how setup  product name from a database and send it to the header template in CodeIgniter

How to manange two different codeigniter session value in localhost?

Hello

Here issue If we Install Two codeigniter in localhost then some time session value config with another codeigniter .

for example

I Have to develope two different different site in login query i am create user_login session for two website same. one site login  it's effect to another site

if one of site logout then second website automatically logout.

for this issue we have to manage config file.

all website set in config file this

$config['sess_cookie_name'] = 'you own name for the session';