Skip to content
  • Home
  • Blog
    • yttags
    • Youtube
  • Categories
  • Tools
  • Server-Side
    • php
    • Node.js
    • ASP.NET
    • Magento
    • Codeigniter
    • Laravel
    • Yii
  • JS
    • AngularJS
    • Ajax
    • VueJs
    • jQuery
    • ReactJS
    • JavaScript
  • Full Form
  • Guest Post
  • Advertise
  • About
  • Contact Us
Pakainfo

Pakainfo

Web Development & Good Online education

PHP CodeIgniter Twitter Login Steps – Full Code

March 27, 2019 Pakainfo Technology, Codeigniter, php, Programming Leave a comment
Rate this post

Today, We want to share with you PHP CodeIgniter Twitter Login Steps.In this post we will show you How to Use the Twitter API with Codeigniter, hear for Login with Twitter in PHP CodeIgniter full code we will give you demo and example for implement.In this post, we will learn about PHP Twitter Login And Integration in PHP Website Tutorial with an example.

PHP CodeIgniter Twitter Login Steps

There are the Following The simple About PHP CodeIgniter Twitter Login Steps Full Information With Example and source code.

As I will cover this Post with live Working example to develop Login With Twitter PHP CodeIgniter, so the Integrate Twitter Login in CodeIgnitor for this example is following below.

How to Auto Post on Twitter using PHP API

Step 1: Download twitter PHP CodeIgnitor library

Free Download twitter PHP library

Read Also:  Angular2 Datatable Pagination, Sorting and Searching

First of all You open your terminal or CDM and run this Commads and free to fill Download Twitter Library in PHP CodeIgnitor

composer require abraham/twitteroauth

Step 2 : Twitter Login config

application/config/constant.php

define("Consumer_Key", "jayPakaiFod896556");
define("Consumer_Secret", "DSPpakajayGonsimp8598Siisksjt");

Step 3: Twitter Authentication

application/libraries/TwitterAuth.php

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

require_once APPPATH.'third_party/twitter-login/lib/autoload.php';
use Abraham\TwitterOAuth\TwitterOAuth;

class TwitterAuth
{
	protected $CI;
    public function __construct()
    {

    	$this->CI =& get_instance();
        $this->CI->load->library('session');        
        $this->connection= new TwitterOAuth(Consumer_Key, Consumer_Secret);        
       
    }
    public function getLogin(){

    	$this->request_token = $this->connection->oauth("oauth/request_token", array("oauth_callback" => base_url()."Dashboardblog/twitterResponse"));
    	// print_r($this->request_token);

        $_SESSION['oauth_token'] = $this->request_token['oauth_token'];
       $_SESSION['oauth_token_secret'] = $this->request_token['oauth_token_secret'];
       $url = $this->connection->url("oauth/authorize", array("oauth_token" => $this->request_token['oauth_token']));

       $this->CI->session->set_userdata('oauth_token', $this->request_token['oauth_token']);
		$this->CI->session->set_userdata('oauth_token_secret',$this->request_token['oauth_token_secret']);
    	
    	redirect($this->connection->url('oauth/authorize', array('oauth_token' => $this->request_token['oauth_token']), 'refresh'));

    }
    public function checkAuth(){

    	$this->connection = new TwitterOAuth(Consumer_Key, Consumer_Secret, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);

		$this->access_token = $this->connection->oauth('oauth/access_token', array('oauth_verifier' => $_REQUEST['oauth_verifier'], 'oauth_token'=> $_GET['oauth_token']));

	    $this->connection = new TwitterOAuth(Consumer_Key, Consumer_Secret, $this->access_token['oauth_token'], $this->access_token['oauth_token_secret']);

	    $this->user_info = $this->connection->get('account/verify_credentials');

	    return $this->user_info;

    }
}

Free Live Chat for Any Issue

Step 4 : Create View Files

display twitter login button.

function index(){
    $this->load->view('twitter_auth');
  }

application/views/twitter_auth.php

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>www.pakainfo.com - Twitter Login using PHP</title>
<style>
.wrapper
{
	width: 800px;
	margin:0 auto;
}
h1
{
	font-size:28px;
	font-family:Gotham, "Helvetica Neue", Helvetica, Arial, sans-serif;
}
</style>
</head>
<body>
<div class="wrapper">
<h1><a href="https://www.pakainfo.com/login-with-facebook-and-twitter/">Twitter Login using TwitterOAuth and PHP</a></h1>
<a href='<?php echo base_url(); ?>Dashboardblog/twitterAuth'><img src='<?php echo base_url(); ?>/upload/img/live_twitter_login_button.png' style='width: 50%;'></a>
</div>
</body>
</html>

How to Send Twitter Automatically Tweets with PHP

Step 5 : PHP codeignitor twitterAuth in controller

load TwitterAuth Library in codeignitor

 public function twitterAuth(){
     $this->load->library('TwitterAuth');
     $this->twitterauth->getLogin();     
    
  }

 public function twitterResponse(){
    $this->load->library('TwitterAuth');
    $this->load->model('User_model');
    $twitter_data = $this->twitterauth->checkAuth();
    $res = $this->User_model->insert_userdata($twitter_data);
    if($res){
      $userdata = array('id'=>$res->id,'firstname'=>$res->firstname,'lastname'=>$res->lastname,'email'=>$res->email,'password'=>$res->password,'user_type'=>$res->user_type);
      $this->session->set_userdata($userdata);
    redirect(base_url('Dashboard/index'));
    }


Twitter Login using TwitterOAuth and PHP
application/models/User_model.php
function check_tuser($data){
  
  $check = $this->ConfirmTwiterUsers($data->id);  
  $users_data = array('twitter_id'=>$data->id,
      'firstname'=>$data->screen_name,
      'location'=>$data->location,
      'profile_pic'=>$data->profile_image_url,
    );
  if(!empty($check) && count($check) > 0 ){    
    $this->db->where('id',$check->id);
    $this->db->update('signup',$users_data);
    return $check;
  }else{
    $this->db->insert('signup',$users_data);     
    return $this->ConfirmTwiterUsers($this->db->insert_id());
  }  
        
}
 
function ConfirmTwiterUsers($id){
  $this->db->select('*');
  $this->db->from("signup");
  $this->db->where('twitter_id',$id);
  $qry = $this->db->get();
  return $qry->row();
}
 

Angular 6 CRUD Operations Application Tutorials

Read :

  • Technology
  • Google Adsense
  • Programming
Read Also:  Login with Facebook using PHP SDK with mysql download

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

Download

I hope you get an idea about PHP CodeIgniter Twitter Login Steps.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Related posts:

  1. Login with Facebook and Twitter
  2. Login with Facebook and Twitter using PHP
  3. html code for login page with username and password validation
  4. Multiple image slider in html source code
  5. how to make a login page in html with database?
  6. jQuery Full screen Navigation Overlay
  7. CodeIgniter Simple User Registration and Login System
  8. PHP CodeIgniter Login with Facebook Step By step
  9. CodeIgniter Login Registration Example Tutorial From Scratch
  10. How to Auto Post on Twitter using PHP API
Read Also:  Laravel 6 Collection Methods with Examples
codeigniter login with facebook and twitterHow to Use the Twitter API with CodeigniterIntegrate Twitter Login in CodeIgnitorLogin with Twitter in CodeIgniterlogin with twitter in phpLogin with Twitter in PHP CodeIgniter full codeLogin With Twitter PHP CodeIgniterphp login with facebook google twitterPHP Twitter Login And Integration in PHP Website Tutorialtwitter api phptwitter login demo in codeignitertwitter-oauth-phptwitteroauth connectiontwitteroauth get

Post navigation

Previous Post:PHP cURL Download File From Url Example
Next Post:Laravel Eloquent JOIN Multiple Tables using Query Builder

Search

Write For Us

We’re accepting well-written informative guest posts and this is a great opportunity to collaborate.
Submit a guest post to [email protected]
Contact Us

Freelance web developer

Do you want to build a modern, lightweight, responsive website quickly?
Need a Website Or Web Application Contact : [email protected]
Note: Paid Service
Contact Me
Cricday

Categories

3movierulz (48) Ajax (464) AngularJS (377) ASP.NET (61) Bollywood (92) Codeigniter (174) CSS (96) Earn Money (61) Education (53) Entertainment (108) fullform (77) Google Adsense (62) Highcharts (77) Hollywood (93) JavaScript (1354) Jobs (39) jQuery (1421) Laravel (1083) LifeStyle (50) movierulz4 (47) Mysql (1029) Mysqli (890) Node.js (38) php (2110) Programming (2320) Python (96) ReactJS (37) Software (102) Software (77) Stories (78) tamilrockers (88) Tamilrockers kannada (48) Tamilrockers telugu (47) Tech (101) Technology (2359) Tips and Tricks (107) Tools (111) Top10 (293) Trading (49) Trending (45) VueJs (250) Web Technology (83) webtools (129) wordpress (165) World (121)

Advertise With Us

Increase visibility and sales with advertising. Let us promote you online.
Click Here

A To Z Full Forms

Access a complete full forms list with the meaning, definition, and example of the acronym or abbreviation.
Click Here

Web Development & Good Online education : Pakainfo by Pakainfo.
Top
Subscribe On YouTube : Download Source Code & New itsolutionstuck
We accept paid guest Posting on our Site : Guest Post Chat with Us On WhatsApp