Tuesday, July 11, 2017

How to configure PHP with Mongodb and sample

Hi All,

It`s simple as mysql db configuration , do not worry about it , please follow below step to run demo application using mango db.

Step ->download  For window enable the driver "extension=mongo.so" 

configure for Ubuntu 14.04, : run "sudo apt-get install php5-mongo "

Step 2 : Download the sample PHP with mongo crud application

Step 3 : Extract CRUD folder into you xampp directory or /var/www/html/

finally run your sample : http://localhost/php-mongodb-crud

hope it will help you :) Enjoy Guys


Some of the below mongodb commands

Please read commands from official mongodb site 

Saturday, January 21, 2017

How to silently or offline post content to users wall Twitter [Solved]

How to silently post share into  Twitter user wall following below  instruction. its difficult if you might be you are going wrong direction . do not worry for this please follow step by step.

Step1- Dowonload Twitter Auth here

Step2-> Create a project folder in xampp/htdoc/TwSilentPost

1. Then create config.php within project folder

<?php
#####################config.php#######################
define('CONSUMER_KEY', 'XXXXXX');
define('CONSUMER_SECRET', 'XXXXXXXXX');
define('OAUTH_CALLBACK', 'http://localhost/TwSilentPost/process.php');
?>

Step2-> Go to Twitter App login create app and input all required information against app

Callback URL :  http://localhost/TwSilentPost/process.php



Step3->create process.php and paste below code

<?php
#######################process.php###############################
session_start();
include_once("config.php");
include_once("inc/twitteroauth.php");
$hostName = 'http://'.$_SERVER['HTTP_HOST'];

if(isset($_REQUEST['oauth_token']) && $_SESSION['token']  !== $_REQUEST['oauth_token']) {

//If token is old, distroy session and redirect user to index.php
session_destroy();
header('Location: index.php');

}elseif(isset($_REQUEST['oauth_token']) && $_SESSION['token'] == $_REQUEST['oauth_token']) {

//Successful response returns oauth_token, oauth_token_secret, user_id, and screen_name
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['token'] , $_SESSION['token_secret']);
$access_token = $connection->getAccessToken($_REQUEST['oauth_verifier']);


if($connection->http_code == '200')
{

//Redirect user to twitter
$_SESSION['status'] = 'verified';
$_SESSION['request_vars'] = $access_token;


$oauth_token = $_SESSION['request_vars']['oauth_token'];
$oauth_token_secret = $_SESSION['request_vars']['oauth_token_secret'];
###############################store auth token and auth secret key in Database table######
##INSTER TABLE (userid,TwAtuhToken,TwAuthSecreet)values(123,$oauth_token,$oauth_token_secret);
##################################################################

header('Location: success_msg.php');
}else{
die("error, try again later!");
}

}else{

if(isset($_GET["denied"]))
{
header('Location: index.php');
die();
}

//Fresh authentication
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
$request_token = $connection->getRequestToken(OAUTH_CALLBACK);

//Received token info from twitter
$_SESSION['token'] = $request_token['oauth_token'];
$_SESSION['token_secret'] = $request_token['oauth_token_secret'];

//Any value other than 200 is failure, so continue only if http code is 200
if($connection->http_code == '200')
{
//redirect user to twitter
$twitter_url = $connection->getAuthorizeURL($request_token['oauth_token']);
header('Location: ' . $twitter_url);
}else{
die("error connecting to twitter! try again later!");
}
}
?>

Step4->Create index.php

<?php
##################index.php########################
echo '<a href="process.php"><img src="images/sign-in-with-twitter.png" width="151" height="24" border="0" /></a>';
?>


Step5-> create postTw.php file for share content to user wall
<?php
##############################postTw.php########################
include_once("config.php");
include_once("inc/twitteroauth.php");

$statusText="hey, this is test.bikash";
$twitter_oauth_token = get access token from db
$twitter_oauth_token_secret           = get access secret key from db
if($twitter_oauth_token_secret!='' && $twitter_oauth_token!='')
{
             $connection = new TwitterOAuth(CONSUMER_KEY,                       CONSUMER_SECRET, $twitter_oauth_token, $twitter_oauth_token_secret);
            $my_update = $connection->post('statuses/update',               array('status' => $statusText));
}



?>
Out put in Twitter wall like, Hope it will help you, please comment if you have any question on this.