Testing!

ChristmasCarnivals Team
12345

December 20, 2011 at 11:09 pm Leave a comment

Post your tweet from twitter api and php

Twitter is the new social media sensational and many application developers want to add twitter with their site. Many times application developers want to send their updates,users comment and other information to twitter from their application. Twitter provides API to use its services.

Here I give you a very simple function that can post your tweet from your application to twitter. This uses cURL.

function postToTwitter($twitterusername,$twitterpassword,$tweet)
{
$host = “http://twitter.com/statuses/update.xml?status=”.urlencode(stripslashes(urldecode($tweet)));

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $host);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERPWD, “$twitterusername:$twitterpassword”);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POST, 1);

$result = curl_exec($ch);
// Look at the returned header
$resultArray = curl_getinfo($ch);

curl_close($ch);

if($resultArray[‘http_code’] == “200”)
{

$status=true;
}
else {

$status=false;

}
return $status;
}

This function posts your tweet successfully with the signature API on twitter.

March 11, 2010 at 7:13 pm 3 comments

Submit Sitemap Dynamically In Search Engines

You know how to submit sitemap of your website in google. Most of the time you do this with your Google Webmaster Tool. You create a google account and use this service. Every time when your sitemap updates you have to resubmit the sitemap manually.
Google provides a very easy method to make your task easy. You just submit your sitemap at once (First time) in Google webmaster , and for resubmitting you can invoke the following URL

http://www.google.com/webmasters/tools/ping?sitemap=http://example.com/sitemap.xml

You can invoke this URL via any PHP program whenever your sitemap updates.

This method is very useful when you deal with dynamic sites where sitemap is automatically generated. Most of the CMS (like drupal) uses above method for resubmitting the sitemap.

The URL shown above is a standard form of sitemap submission in search engines and most of the popular search engines follow this. For example if you have to submit your sitemap in BING just invoke the following URL
http://www.bing.com/webmaster/ping.aspx?sitemap=http://example.com/sitemap.xml

Similarly for ASK.com

http://submissions.ask.com/ping?sitemap=http://example.com/sitemap.xml

And for yahoo

http://search.yahooapis.com/SiteExplorerService/V1/ping?sitemap=http://example.com/sitemap.xml

March 10, 2010 at 7:20 pm Leave a comment

Database engines in MySQL. MyISAM and InnoDB

What is a Database Engine?
A database engine is basically a software layer in every DBMS that creates table, updates them and retrieves information from them. Since data and database may be of different natures MySQL DBMS provides several kinds of DBMS engines. We discuss two of them, that are most popular-

1)MyISAM

MyISAM is the default database engine of MySQL, that is based on ISAM (Index Sequential Access Method). ISAM was developed by IBM for fast retrieval of data in Mainframe Computers. MyISAM is fast in data access and supports full text searching. The limitation of this is, MyISAM is not suitable for transactional tables or it does not support foreign key constraints. (i.e. referential integrities). This is poor in crash recovery also. MyISAM locks the table until the operation is not complete. For example if you are inserting a row, the next operation say ‘updating of row ‘will wait until the first finishes.

2) InnoDB

InnoDB is more safe database engine of MySQL. InnoDB is good for transactional tables. It supports foreign key constraints. COMMIT, ROLLBACK sort of operations can be performed in this engine. Crash recovery is more easy in this. This stores data in clustered indexes (Storing the rows in primary key order while MyISAM stores the rows as they added). InnoDB is designed for large volume of data for high performance. This is also good for multi-user concurrency.

November 23, 2009 at 2:39 pm 2 comments

How to write file without 777 permission

File writing is a very important part in PHP programming. We need to do this many time.  Every time when you do this, you need to give  777 permission to the directory  in which you are going to write the file.By this you become eligible for creating , writing,reading and deleting the file by your PHP code.  This is not a secure way. Giving this permission to any of you directory can create big security problems. And of course your server guys will never suggest you to do this.

So what to do – Either go for less featured permissions (775 , 770 etc) but they have their own restrictions. Here I give you a way to write  the file without bothering of your directory permissions. This way is to write file through FTP. PHP has a strong collection of FTP functions that are very useful in file writing. With the help of this you can easily write your file without fighting with your server guys for specific permissions.

Here is the code of file writing though PHP..

<?php

/*
################################# File Writing Through FTP ##########################
Subject      :File writing through FTP (An alternative of 777 permission )

*/

Class ftpUtility
{

/*
* variable declarations
*/

var $ftpHost;
var $ftpUser;
var $ftpPassword;
var $ftpstream;

/*
* @param1 is the name of the FTP Host where you want to write the file
* @param2 is the user name of the FTP Host where you want to write the file
* @param3 is the password of the FTP Host where you want to write the file
*/

function __construct($host,$user,$pass)
{
$this->ftpHost=$host;
$this->ftpUser=$user;
$this->ftpPassword=$pass;
$this->ftpstream=ftp_connect($this->ftpHost);

}

/*
Checks the FTP connection.
*/

function checkFTP()
{

if(ftp_login($this->ftpstream, $this->ftpUser,$this->ftpPassword))
return true;
else
return false;

}

/*
/*@Param1 is the path where you want to write the file
/*@Param2 is the content that is to be written in the file

*/

function ftpWrite($filePath,$content)
{
$temp = tmpfile();
fwrite($temp,$content);
fseek($temp,0);

$upload=ftp_fput($this->ftpstream, $filePath,$temp,FTP_BINARY);

if($upload)
return true;
else
return false;

}

/* Close FTP stream */
function ftpclose()
{
ftp_close($this->ftpstream);
}

}

############################################### File Writing #########################################

$ftpHost=”www.example.com”;
$ftpUser=”XXXXXXXXXXXXXXXXXXX”;
$ftpPassword=”XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX”;
$filePath = “public_html/testing/myfile.txt”;
$content=”My FTP test”;

$ftp=new ftpUtility();

if($ftp->checkFTP())
{

if($ftp->ftpWrite($filePath,$content))
echo “Cheers! Check your file!”;
else
echo “Error: Try again.”;

}
$ftp->ftpclose();

?>

NOTE: You can use either the FTP details of root or can create separate FTP credentials of the directory in which you wanna perform the action (Your server guys can help you in second option)

November 15, 2009 at 11:27 am 3 comments

How to post photos in flickr through API and PHP

Hi All,

Now its very easy to upload photos in flickr from your own site or application.  This can be done through the help of  phpFlickr class.  This can be downloaded from http://phpflickr.com or directlink for downloading  is http://code.google.com/p/phpflickr/downloads/list

Including this class in following code you can easily upload images in your flickr account.

<?php
include(“phpFlickr.php”);

$api_key= “XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX”;

$api_secret= “XXXXXXXXXXXX”;

$flickr = new phpFlickr($api_key, $api_secret,true);

$flickr->auth(“write”);

//you can use relative path here too like /home/example/public_html/snaps/a.jpg
$path=”a.jpg”;

$response=$flickr->sync_uploa d(“$path”,”put your description here”,”mytag1,mytag2″,1,1,1);

//returns the id of the image that is posted in flickr
if($response)
{
header(“Location:http://flickr.com&#8221;);
exit();
}

?>

While executing this code, flickr  asks you for a yahoo login (If not logged in).After login it  asks  you to allow the application to access your flickr accaount. Once you allow this, the image is posted in flickr and the script gives you the image id of the posted image.

Then it redirects you to the flickr to show the picture you posted.

Thanks!

November 6, 2009 at 11:29 am 3 comments

How to develop a twitter application through twitter API

Since, twitter has changed the world of Internet and of course it has given a new way of application development. Now you can easily develop an application for twitter and use twitter’s user base to promote your application. Since twitter has great traffic ,you can easily take the advantage of it. The best examples of this are twitpic, twitsnaps, digsby,twitterfeed,twhirl etc. To develop a killer twitter application you need two things essentially.

1)A unique idea

2)Twitter’s API🙂

So idea is yours and API is of twitter, and I tell you how to use it.

Twitter has two kinds of APIs.

1)Non Oauth

2)Ouath

Before discussing on APIs, I just explain you first what is Oauth. Oauth is basically an open protocol to allow secure API authorization in a simple and standard method from desktop and web applications.Oauth came in existence in 2006 and twitter adopted this in the early of 2009. Previously twitter has non oauth APIs. Most of the famous twitter applications are developed in this. You can use this for such APIs  http://uurl.in/Haw2i

In Non Oauth APIs you directly need the user information like userid,password to access the features. If you are using such APIs user’s twitter login credentials are in your control. You can save them. Like in case of twitpic you give your twitter userid and password to twitpic. Twitpic may save it🙂.Such APIs need user’s exact userid and password to access them properly.

In Oauth APIs you need an authentication token that will be given from twitter only. For such applications you will have to register yourself with twitter. After registration,twitter will give you a Consumer Key and Consumer Secret Key. That you need to use in your source code. In these applications an authentification url is given by twitter to login. When user clicks on that login url , it takes user to twitter where user has to enter his userid and password, if it successful then twitter redirects it to your callback URL (url of your application,that you define when you register with twitter) along with a unique oauth token. On the basis of that token you can use the API to access its features. This is considerd as secure from user’s point of view because user’s login information is secure and you can not catch it.

Now most of the users prefer oauth based applications. But still twitter’s Oauth API is not as good as its Non Oauth API for desktop or mobile applications.Since they are improving this.

You can register your application for Oauth from http://twitter.com/oauth_clients

And the help is available on http://apiwiki.twitter.com/OAuth-FAQ

To know about Oauth visit http://oauth.net/

August 8, 2009 at 9:25 am 12 comments

Older Posts