libpurple is intended to be the core of an IM program.

This libpurple PHP binding, which defines a set of internal classes, gives a possibility to use aol and icq (oscar), yahoo, msn, jabber, irc and much more protocols directly from PHP. Write your own IM chat client in PHP, as simply as PHP enables it.

Download latest version of “phurple” from here

http://sourceforge.net/projects/phurple/
# yum install pidgin
# yum install libpurple-devel
# wget http://nchc.dl.sourceforge.net/project/phurple/phurple/phpurple-0.4.0-alpha/phurple-0.4.0-alpha.tar.bz2
# bunzip2 phurple-0.4.0-alpha.tar.bz2; tar xvf phurple-0.4.0-alpha.tar
# cd phurple-0.4.0-alpha
# phpize && ./configure –enable-phurple && make
# make install

Now we find phurple.so in /usr/lib/php/modules…
Make a phurple.ini in /etc/php.d add extention phurple.so in it 😉


phurple

Phurple Reference: http://phurple.php.belsky.info/

Sometime we face the problem when we navigate from HTTP URL to HTTPS URL our session lost.

You can manage session between HTTP to HTTPS or HTTPS to HTTP:

1. Transmit session ID between page using GET

2. POST session ID by POST

3. Use files to save sessions

4. Use Cookies for sessions

5. Use database to save session

Below example can be used to transmit using GET….

File : http.php
……………

<?php

session_start();

$sessionID = session_id();

$_SESSION[‘phpsolutions’] = ‘Demo session between HTTP HTTPS’;

echo ‘<a href=”https://www.phpsolutions.co.in/https.php?session=’.$sessionID.'”>Demo session from HTTP to HTTPS</a>’;

?>

File: https.php
……………

<?php

$sessionID = $_GET[‘session’];

session_id($sessionID);

session_start();

if (!empty($_SESSION[‘phpsolutions’])) {
echo $_SESSION[‘phpsolutions’];
} else {
echo ‘Demo session failed’;
}

?>
IE7 : This page contains both secure and nonsecure items

You have to use relative path for all static resource on page like css, js, images, flash etc. to avoid IE message secure and nonsecure items…

IE message

IE message

Well! stay with us….. 🙂

Facebook Application

On March 20, 2010, in PHP, Tips, Tricks, by phpsolutions
PHP Solutions on Facebook

PHP Solutions on Facebook

FaceBook Application
FaceBook Profile

FFmpeg

On March 20, 2010, in CentOS, Fedora, Linux, Open Source, Tips, Tricks, Web Application, by phpsolutions
FFmpeg

FFmpeg

# ffmpeg is a command line tool to convert one video file format to another. It can also grab and encode in real time from a TV card.
# ffserver is an HTTP and RTSP multimedia streaming server for live broadcasts. It can also time shift live broadcast.
# ffplay is a simple media player based on SDL and on the FFmpeg libraries.
# ffprobe is a command line tool to show media information.

# Convert video files into another format.
# flv -> avi
# flv -> mp4
# flv -> wmv
# flv -> swf
# avi -> mp4
# avi -> wmv
# avi -> flv
# avi -> swf
# mp4 -> avi
# mp4 -> wmv
# mp4 -> flv
# mp4 -> swf
# wmv -> mp4
# wmv -> avi
# wmv -> flv
# wmv -> swf
# divx -> mp4
# divx -> avi
# divx -> flv
# divx -> wmv
# divx -> swf
#
# Audio extraction
# flv -> mp3
# avi -> mp3
# mp4 -> mp3
# wmv -> mp3
# divx -> mp3
# swf -> mp3

if ($target == ‘mp3’)
{
$ffmpeg_cmd = exec($ffmpeg.” -y -i “.$source.” -acodec “.$acodec.” -vn “.$target);
} else {
$ffmpeg_cmd = exec($ffmpeg.” -y -i “.$source.” -acodec “.$acodec.” “. $ar .” -ab 128kb “.$vcodec.” “.$r.” -b 1200kb -mbd 2 -cmp 2 -subcmp 2 “.$size.” “.$aspect.” “.$target);
}

PHP – File Upload Stream

On March 17, 2010, in CakePHP, Fedora, Linux, PEAR, PHP, Tips, Tricks, Web Application, by phpsolutions
File Upload Stream

File Upload Stream

PHP supports upload file stream… we can stream data to server using PHP stream_open() & stream_write() functions.

There is alternate method in PEAR to transfer files to server1 to server2. PEAR have HTTP package for uploading files.

HTTP_Request supports GET/POST/HEAD/TRACE/PUT/DELETE, Basic authentication, Proxy, Proxy Authentication, SSL, file uploads etc.

<?php
require_once "HTTP/Request.php";
$req =& new HTTP_Request("http://domain.com/upload");
$req->setBasicAuth("login", "pass");
$req->setMethod(HTTP_REQUEST_METHOD_POST);

$result = $req->addFile("data", "/home/phpsolutions.mp4");
if (PEAR::isError($result)) {
echo "Error occurred during file upload!";
} else {
$response = $req->sendRequest();
if (PEAR::isError($response)) {echo "Error occurred during file upload!";
} else {
echo "File successfully uploaded!";
}
}
?>

Linux Network Configuration

On March 15, 2010, in CentOS, Fedora, Linux, Tips, Tricks, by phpsolutions

# system-config-network
# redhat-config-network
# vi /etc/resolve.conf
# vi /etc/hosts
# /sbin/ifconfig eth0 192.168.10.120 netmask 255.255.255.0 broadcast 192.168.10.255

# /etc/init.d/network restart

ifup – bring a network interface up

ifdown – take a network interface down

system-config-network-screen

system-config-network_Devices-Edit-General

system-config-network_SetHostnameDNS

system-control-network

First you have to download oAuth from github

“An open protocol to allow secure API authorization in a simple and standard method from desktop and web applications.”

7 Simple Steps to create Twitter Application using Twitter’s OAuth….

1. Build TwitterOAuth object

Login to twitter and register a new application here https://twitter.com/oauth_clients … after registering application save consumer key and consumer secret.

$to = new TwitterOAuth($consumer_key, $consumer_secret);

Twitter OAuth

2. Request tokens from twitter

$tok = $to->getRequestToken();

3. Build authorize URL

$request_link = $to->getAuthorizeURL($token);

4. Send user to Twitter’s authorize URL

Twitter_1268502547513

5. Get access tokens from twitter

$tok = $to->getAccessToken();

6. Rebuild TwitterOAuth object

$to = new TwitterOAuth($consumer_key, $consumer_secret, $user_access_key, $user_access_secret);

7. Query Twitter API with new access tokens

$content = $to->OAuthRequest(‘https://twitter.com/account/verify_credentials.xml’, array(), ‘GET’);

$content = $to->OAuthRequest(‘https://twitter.com/statuses/update.xml’, array(‘status’ => ‘Test OAuth update. #testoauth’), ‘POST’);Twitter - Redirecting you back to the application_1268502564768

Source:
https://docs.google.com/View?docID=dcf2dzzs_2339fzbfsf4
http://wiki.github.com/abraham/twitteroauth/links

PEAR is a framework and distribution system for reusable PHP components.

How we get PEAR packages with php files?

Add block of code to the php file….

<?php
// include PEAR class
include (“Date.php”);

// initialize Date object
$d = new Date(“1981-08-07 01:30:11”);

// retrieve date to display
echo $d->getDate();

// retrieve date as formatted string
echo $d->format(“%A, %d %B %Y %T”);

?>

Output:
1981-08-07 01:30:11
Friday, 07 August 1981 01:30:11

Converting between time zones

<?php
// include class
include (“Date.php”);

// initialize object
$d = new Date(“1981-08-07 10:36:27”);

// set local time zone
$d->setTZByID(“GMT”);

// convert to foreign time zone
$d->convertTZByID(“IST”);

// retrieve converted date/time
echo $d->format(“%A, %d %B %Y %T”);
?>

Output:
Thursday, 07 August 1981 16:06:27

Calculating GMT offsets

<?php
// include class
include (“Date.php”);

// initialize object
$d = new Date(“2006-08-08 10:26:27”);

// set local time zone
$d->setTZByID(“PST”);

// get raw offset from GMT, in msec
echo $d->tz->getRawOffset();
?>

Adding and subtracting timespans

<?php
// include class
include (“Date.php”);

// initialize object
$d = new Date(“1951-09-13 16:55:11”);

// add 01:20 to it
$d->addSpan(new Date_Span(“0,1,20,0”));

// subtract 00:05 from it
$d->subtractSpan(new Date_Span(“0,0,5,0”));

// retrieve date as formatted string
echo $d->format(“%A, %d %B %Y %T”);
?>

PHP have rich library to manage “Daylight saving time”… we can use PEAR for DST

United States begins Daylight Saving Time at 2:00 a.m. on the second Sunday in March and reverts to standard time on the first Sunday in November.

Daylight Saving Time

Daylight Saving Time

Enjoy programming with PEAR…. 😉

Install the Alternative PHP Cache (APC)

On February 24, 2010, in CakePHP, CentOS, Fedora, Linux, Open Source, PHP, Tips, by phpsolutions

The Alternative PHP Cache (APC) is a free, open, and robust framework for caching and optimizing PHP intermediate code.

yum install php-pear
yum install php-devel httpd-devel
yum groupinstall ‘Development Tools’
yum groupinstall ‘Development Libraries’
pecl install apc

http://si2.php.net/manual/en/install.pecl.php

Install Fonts in Fedora

On February 24, 2010, in CentOS, Fedora, Linux, Open Source, Tips, Tricks, by phpsolutions

1. Log in as root or use su at command line
$ su
2. Go to the font storage directory:
# cd /usr/share/fonts
3. Create a subdirectory for the Arial fonts:
# mkdir arial
4. Copy the Arial fonts into this directory from font sites or windows FONTS folder.
5. Make the font files accessible systemwide:
# chmod 0775 -R arial
6. Run fc-cache to cache the arial fonts on system:
# fc-cache arial