RSS

Monthly Archives: March 2010

Session lost when switching from HTTP to HTTPS in PHP

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[‘svnlabs’] = ‘Demo session between HTTP HTTPS’;

echo ‘<a href=”https://www.svnlabs.com/https.php?session=&#8217;.$sessionID.'”>Demo session from HTTP to HTTPS</a>’;

?>

File: https.php
……………

<?php

$sessionID = $_GET[‘session’];

session_id($sessionID);

session_start();

if (!empty($_SESSION[‘svnlabs’])) {
echo $_SESSION[‘svnlabs’];
} 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….. 🙂

 

Tags: , , , ,

VideoAPI

a2zVideoAPI

a2zVideoAPI

 
Leave a comment

Posted by on March 24, 2010 in javascript, php, Tips, Tricks, Web Services

 

Tags: , , , ,

Facebook Application

Seven Version on Facebook

Seven Version on Facebook

FaceBook Application
FaceBook Profile

 
1 Comment

Posted by on March 20, 2010 in php, Tips, Tricks

 

Tags: , , , ,

FFmpeg

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);
}

 

Tags: , , , , , ,

PHP – File Upload Stream

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/svnlabs.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!";
}
}
?>
 
1 Comment

Posted by on March 17, 2010 in CakePHP, Fedora, Linux, PEAR, php, Tips, Tricks, Web Application

 

Tags: , , , , , ,

Linux Network Configuration

# 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

 
Leave a comment

Posted by on March 15, 2010 in CentOS, Fedora, Linux, Tips, Tricks

 

Tags: , , , , , , , , , , ,

7 Simple Steps to create Twitter Application

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&#8217;, array(), ‘GET’);

$content = $to->OAuthRequest(‘https://twitter.com/statuses/update.xml&#8217;, 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

 

Tags: , , ,

How to Create OpenSearch Plugins?

browser search plugin

browser search plugin

OpenSearch is a collection of simple formats for the sharing of search results.

OpenSearch description file

http://www.svnlabs.com/opensearch.xml

We have to create  a simple xml file for websites and search engines to publish search results in a standard and accessible format.

See below the code in action…….

<?xml version=”1.0″ encoding=”UTF-8″?>

<OpenSearchDescription xmlns=”http://a9.com/-/spec/opensearch/1.1/”&gt; <ShortName>svnlabs</ShortName>

<LongName>svnlabs – Concentrate > Observe > Imagine > Launch</LongName>

<Description>Search through articles posted on svnlabs.com</Description>

<InputEncoding>UTF-8</InputEncoding>

<OutputEncoding>UTF-8</OutputEncoding>

<AdultContent>false</AdultContent>

<Language>en-us</Language>

<Developer>svnlabs</Developer>

<Contact>svnlabs@gmail.com</Contact>

<Description>svnlabs – Concentrate – Observe – Imagine – Launch svnlabs, Linux, Apache, Mysql, PHP, Video Encoding, Youtube API, Facebook API, Twitter API, Amazon Web Service, OSCommerce, Joomla, WordPress</Description>

<Tags>svnlabs Linux Apache Mysql PHP Video Encoding Youtube API Facebook API Twitter API Amazon Web Service OSCommerce Joomla WordPress</Tags>

<Attribution>Search Articles on svnlabs, http://www.svnlabs.com/</Attribution&gt; <SyndicationRight>open</SyndicationRight>

<Query role=”example” searchTerms=”India”/>

<Image height=”16″ width=”16″ type=”image/vnd.microsoft.icon”>http://www.svnlabs.com/favicon.ico</Image&gt;

<Image height=”130″ width=”130″ type=”image/jpeg”>http://www.svnlabs.com/sv.jpg</Image&gt;

<Url type=”text/html” template=”http://blog.svnlabs.com/?s={searchTerms}”/>

</OpenSearchDescription>

Paste below block of code to HTML Heading section to add browser search plugin….

<link rel=“search” type=“application/opensearchdescription+xml” href=”http://www.svnlabs.com/opensearch.xmltitle=“svnlabs blog search” />

Source:
https://developer.mozilla.org/en/Creating_OpenSearch_plugins_for_Firefox

 
Leave a comment

Posted by on March 7, 2010 in Java, javascript, Linux, php, Tips, Tricks

 

Tags: , , , , ,

Magic of PEAR – Date TimeZone

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…. 😉

 

Tags: , , , , , , , , , ,