Web hosting

Wednesday, March 28, 2012

Solution for facebook logouturl not working

we can get the user information,facebook loginUrl and logoutUrl from the below code using facebook SDK. but now the logoutUrl is not working in facebook by using below code 

$config = array(
'appId'  => '1234',
'secret' => '123456789','fileUpload' => true// Indicates if the CURL based @ syntax for file uploads is enabled. $user_id $facebook->getUser();
// We may or may not have this data based on whether the user is logged in.
        // If we have a $user id here, it means we know the user is logged into
        // Facebook, but we don't know if the access token is valid. An access
        // token is invalid if the user logged out of Facebook.
$profile null;

$userInfos   $facebook->api('/'.$user);
            try {
// Proceed knowing you have a logged in user who's authenticated.
$profile $facebook->api('/me?fields=id,name,link,email');
$fql    =   "select name, location, sex, pic_square from user where uid=" $user;
$param  =   array(
'method'    => 'fql.query',
'query'     => $fql,
'callback'  => ''
$fb_data = array(
'me' => $profile,
'uid' => $user_id,
'loginUrl' => $facebook->getLoginUrl(),
'logoutUrl' => $facebook->getLogoutUrl(),

The above fetch logourUrl is not working

if try below code ie to find facebook logoutUrl separate. its a valid logoutUrl its working for me

function get_logout_url(){//return the facebook logoutUrl

return  $facebook->getLogoutUrl();

Sunday, March 25, 2012

facebook FQL multi Query using graph api

Facebook has a SQL like query language, FQL,  which allows you to request various data points about your pages, applications, etc. When you need a single data point like your page's total fans, you make a call to the method, fql.query to get your data. For a single data point this is great, but what if you are building a chart and need more than one data point? Making repeated calls to Facebook, will quickly begin to become tedious and slow. Luckily, Facebook has another method, fql.multi-query, which allows you to submit multiple queries at the same time and receive them back in a single result-set.

Friday, March 23, 2012

Facebook FQL query using graph api

we can run facebook FQL  query using the graph api.
Here example to get facebook photos from facebook album
First we need to include the facebook class then create an object of facebook class
by using a simple example of FQL query we get an array of details of photos of particular album

require '../src/facebook.php';

 $facebook = new Facebook(array(
'appId'  => '...',
'secret' => '...'));

function get_photos_by_album_id($album_id){

$fql            =   'SELECT pid,src_big,owner,link,position,created,caption,src FROM photo WHERE aid="'.$album_id.'"';
$param  =   array(
'method'    => 'fql.query',
'query'     => $fql,
'callback'  => ''
$fqlResult   =   $facebook->api($param);


Wednesday, March 21, 2012

Create photo albums and upload photos using the Facebook

By using Facebook graph API allow us to access public information like user's first name, last name and profile picture are publicly available. To get additional access like upload photos,create albums,you must first get their permission.

The code example assumes that you have already generated an authenticated session while generating the loginUrl we need to specify scope for the permission (photo_upload, user_photos)

 require '../src/facebook.php';$facebook = new Facebook(array(
'appId'  => '...',
'secret' => '...'));$loginUrl=$facebook->getLoginUrl( array(
'scope'         'email,
echo "<script type="text/javascript">
top.location.href = '
// ]]></script>";?>

 permission popup once we get the permission from user we can able to upload the photos to there albums

The following snippet creates a photo album and then uploads a photo into it:


//Create an album
$album_details = array(
message'=> 'Album desc',
name'=> 'Album name'
$create_album = $facebook->api('
/me/albums', 'post', $album_details);

//Get album ID of the album you'
ve just created
//Upload a photo to album of ID...$photo_details = array(
'message'=> 'Photo message');$file='app.jpg'//Example image file$photo_details['image'] = '@' realpath($file);
$upload_photo $facebook->api('/'.$album_uid.'/photos''post'$photo_details);?>

 Supported Image Types You can upload the following image file formats through this call: *GIF *JPG *PNG *PSD *TIFF *JP2 *IFF *WBMP *XBM Facebook SDK

Tuesday, February 21, 2012


Here's how you execute a POST using the PHP CURL library.

//define post values 
$message="test message ";//define post url
$url="http://localhost/WebServices/";//encode the message
$message urlencode($message);//initialize the curl
$ch curl_init();

 if (!
"Couldn't initialize a cURL handle");
//setting options
$ret curl_setopt($chCURLOPT_URL,$url);
curl_setopt ($chCURLOPT_POST1);
curl_setopt($chCURLOPT_SSL_VERIFYHOST2);//setup post fields
curl_setopt ($chCURLOPT_POSTFIELDS,"Message=$message");
$ret curl_setopt($chCURLOPT_RETURNTRANSFER1);//If you are behind proxy then please uncomment below line and provide your proxy ip with port.
// $ret = curl_setopt($ch, CURLOPT_PROXY, "PROXY IP ADDRESS:PORT");

//execute and geting response
$curlresponse curl_exec($ch);

'curl error : 'curl_error($ch);

 if (empty(
$ret)) {
// some kind of an error happened
curl_close($ch); // close cURL handler
} else {
$info curl_getinfo($ch);
curl_close($ch); // close cURL handler
    //echo "<br>";
echo $curlresponse;    //echo "post message Sent Succesfully" ;

Email Script in PHP

Below script is simple email script in php. by using mail function

// Email destination address
 $to 'to@email.com'; 
// Email Subject
 $subject 'PHP Simple Mailer Example'; 
// Email message 
$content 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
 Etiam sit amet elit vitae arcu interdum ullamcorper.'; 
// Additional headers

$headers  'MIME-Version: 1.0' "\n";
$headers .= 'Content-type: text; charset=iso-8859-1' "\n"; 
$headers .= 'From: from@email.com';


Thursday, February 16, 2012

codeigniter error reporting handling

1. Turn off PHP Errors with error_reporting(0)In the root directory of your CodeIgniter installthere is an index.php fileThe first option in there is ‘PHP ERROR REPORTING LEVEL’.

 Set it to zero:error_reporting(0);CodeIgniter version 2.0.1 and above have an environment constant in the index.php file as wellSetting this to “production” will disable all PHP error outputRead more about this on the Codeigniter User Guide page on Security and on Handling Environments. 

2. Turn off Database Errors in Config
The PHP errors are off
but any MySQL errors are still going to showTurn these off in the /config/database.php fileSet the db_debug option to false: 

$db['default']['db_debug'] = FALSE; 

3. Adjust Error Logging Threshold
/config/config.php file has a log threshold optionIt states “For a live site you’ll usually only enable Errors (1to be logged otherwise your log files will fill up very fast.

['log_threshold'] = 1; 

4. Turn on all Errors in Config
In the root directory of your CodeIgniter install
there is an index.php fileThe first option in there is ‘PHP ERROR REPORTING LEVEL’Set it to :

CodeIgniter tutorials .htaccess Setup

CodeIgniter provides the option to use Search Engine friendly URL’s in your application. Search Engine friendly URL’s let’s spiders index your site better and are visually more attractive.

mod_rewrite and the Index page

Before anything else, make sure you have mod_rewrite enabled on your server. Once that’s taken care of, edit your index.php file and set $config['index_page'] to blank.
$config['index_page'] = ”;

Creating the .htaccess file

Go to your root directory, create a file called “.htaccess” and paste the following.


# Set the default file for indexes

DirectoryIndex index.php
# mod_rewrite rules

RewriteEngine on
# The RewriteBase of the system (if you are using this system in a sub-folder).

# RewriteBase /SubFolderName/
# This will make the site only accessible without the “www.”

# (which will keep the subdomain-sensive config file happy)

# If you want the site to be accessed WITH the “www.”

# comment-out the following two lines.

# RewriteCond %{HTTP_HOST} ^www\.site\.com$ [NC]

# RewriteRule ^(.*)$ http://site.com/$1 [L,R=301]
# If a controller can’t be found – then issue a 404 error from PHP

# Error messages (via the “error” plugin)

# ErrorDocument 403 /index.php/403/

# ErrorDocument 404 /index.php/404/

# ErrorDocument 500 /index.php/500/
# Deny any people (or bots) from the following sites: (to stop spam comments)

# RewriteCond %{HTTP_REFERER} nienschanz\.ru [NC,OR]

# RewriteCond %{HTTP_REFERER} porn\.com

# RewriteRule .* – [F]

# Note: if you are having trouble from a certain URL just

# add it above to bock all visitors from that site.
# Or you can also uncomment this if you know the IP:

# Deny from
# If the file is NOT the index.php file

RewriteCond %{REQUEST_FILENAME} !index.php
# Hide all PHP files so none can be accessed by HTTP

RewriteRule (.*)\.php$ index.php/$1
# If the file/dir is NOT real go to index

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php/$1 [QSA,L]
# If mod_rewrite is NOT installed go to index.php
ErrorDocument 404 index.php


codeigniter tutorials for beginners

CodeIgniter – Getting Started

Become a CodeIgniter Pro in 15 Days!

Other Sample CodeIgniter Tutorials Worth Reviewing

To Get Last Insert Id in CodeIgniter Mysql

// Basic php mysql method 


 // CodeIgniter method 

Wednesday, February 15, 2012

How to Refresh Current Page in CodeIgniter


Set and Delete Cookies at CodeIgniter

$cookie = array(
    'name'   => 'loggedin',
    'value'  => 'yes',
    'expire' => '86500',
    'domain' => '.apol0829.dev',
    'prefix' => 'apollidon_'
$cookie = array(
    'name'   => 'loggedin',
    'value'  => '',
    'expire' => '0',
    'domain' => '.apol0829.dev',
    'prefix' => 'apollidon_'

Multiple Database Connection in CodeIgniter

The database.php config file 
$active_group "default";
$active_record TRUE;
$db['default']['hostname'] = "localhost";
$db['default']['username'] = "root";
$db['default']['password'] = "123456";
$db['default']['database'] = "database_1";
$db['default']['dbdriver'] = "mysql";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";
$db['second_db']['hostname'] = "localhost";
$db['second_db']['username'] = "root";
$db['second_db']['password'] = "abcdef";
$db['second_db']['database'] = "database_2";
$db['second_db']['dbdriver'] = "mysql";
$db['second_db']['dbprefix'] = "my_";
$db['second_db']['pconnect'] = TRUE;
$db['second_db']['db_debug'] = TRUE;
$db['second_db']['cache_on'] = FALSE;
$db['second_db']['cachedir'] = "";
$db['second_db']['char_set'] = "utf8";
$db['second_db']['dbcollat'] = "utf8_general_ci";

The default group will be loaded automatically during $this->db call. You can use CI legacy_db method to load other db configuration group.

// load second database
$this->legacy_db $this->load->database(database_2true);
// fetch result from my_table
$this->legacy_db->select ('*');
$this->legacy_db->from ('my_table');
$query $this->legacy_db->get();
$result $query->result ();

CodeIgniter: Payment Gateway using Authorize.net Library

First, download the Authorize.net library for CodeIgniter from here :
Download Authorize.net CodeIgniter Library »
Put the lib on your libraries directory, then load it as follow :

// Load authorize_net library


// Invoke Authorize.net service 



$response $this->authorize_net->response();

CodeIgniter: Convert XML into Object

Codeigniter library that help you convert and parse xml data into php object

<?phpclass CI_Xml_Handle{
XMLtoObject () {
        try {
$xml_object = new SimpleXMLElement($this->xml);
            if (
$xml_object == false) {
        catch (
Exception $e) {

This library works as an XML parser and convert any XML document to an object for further processing. Just copy and paste source code above, create a CodeIgniter library file, put it in usual CodeIgniter library folder, load it, and call it ;)

How to Create Star Rating using CodeIgniter and jQuery Star Rating Plugin

$(function() {
            required: true,
            callback: function(value, link) {
                type: "post",
                url: site_url + "user/rate",
                dataType: "json",
                data: "&post_url=" + $('#post_url').val() + "&rate_val=" + value,
                success: function(e) {
                    $.jGrowl(e.code + "<br>" + e.msg);
On the code snippet above, we implement the rating plugin on the HTML element which has "star-radio" class attribute, which is your radio button as rating control. Every time user rate to a post, the script will send an Ajax request to User controller and send the rate data to the "rate" function.
    // .. some User controller code up here
    // Rate function on User Controller
    public function rate()
        // Turn of layout for Ajax request
        // Gather ajax post data
        $rate = $this->input->post("rate_val", true);
        $post_url = $this->input->post("post_url", true);
        // Load model data
        $post_id = $this->Post->get_post_id($post_url);
        // Call function to check if user is login
        // return current login user id, null if not login yet
        // You need to define this helper function your self
        if (get_user_id()) {
            // Call the Post Model is_rated method to check whether the current login user has submit a rate to related post
            if (!$this->Post->is_rated(get_user_id(), $post_id))
                $data = array("post_id" => $post_id,
                    "user_id" => get_user_id(),
                    "posts_rating_value" => $rate,
                    "posts_rating_date" => date("Y-m-d H:i:s")
                // Call Post model method to insert rating data
                if ($this->Post->insert_rating($data, $post_id, $rate)) {
                    echo json_encode(array("code" => "Success", "msg" => "Thank you, rate has been submitted"));
                else {
                    echo json_encode(array("code" => "Error", "msg" => "Sorry, something wrong. Please try again."));
            // If post has been rated by the current login user
            else {
                echo json_encode(array("code" => "Error", "msg" => "You have already rated this post"));
        // User is not login yet, ask them to login first
        else {
            echo json_encode(array("code" => "Error", "msg" => "Please login to submit this rate"));
        // Do not proceed to view, just terminate to send Json response
    // .. any other User controller code goes here
Following is the CodeIgniter View sample code for the rating control on your post view:
//Check if user logged in
if (!get_user_id()) {
    $radioIsActive = "disabled=disabled ";
else {
    $radioIsActive = " ";
for ($i = 1; $i <= 5; $i++) :
    if ($i == round($row["average"])) :
    <input class="star-radio" type="radio" name="rating" value="<?php echo $i; ?>" checked="checked" <?php echo "$radioIsActive"; ?>/>
    <?php else: ?>
    <input class="star-radio" type="radio" name="rating" value="<?php echo $i; ?>" <?php echo "$radioIsActive"; ?>/>

CodeIgniter Tutorial: Use Pagination Class


Create a blogs table using sql below: 
CREATE TABLE `db_name`.`blog` (
    `title` VARCHAR( 200 ) NOT NULL ,
    `desc` TEXT NOT NULL ,
    `created` DATETIME NOT NULL ,
    `modified` DATETIME NOT NULL

CodeIgniter Model

class blog extends Model
    function blog()
    function count_blogs()
        // Count total numbers of blog entries
        $query = $this->db->query('SELECT count(*) as count_blog FROM blogs');
        $result = $query->results();
        return $result[0]->count_blog;
    function select_blogs($num, $offset)
        // Fetch data from blogs table
        $query = $this->db->get('blogs', $num, $offset);
        $result = $query->results();
        return $result;

CodeIgniter Controller

class blog extends Controller
    function blog() {
    function bloglist() {
        $config['base_url'] = ‘http://your-site.com/index.php/test/page/’;
        $config['total_rows'] =$data['count_blog'];
        $data['title']=’CodeIgniter Pagination Example’;
        $data['bloglist'] = $this->blog->select_blogs($config['per_page'],$this->uri->segment(3));
        // This will generate your pagination links

CodeIgniter View

    <?php for ($i=0; $i < count($bloglist); $i++) : ?>
        <td><?php echo $bloglist[$i]->title; ?></td>
        <td><?php echo $bloglist[$i]->desc; ?></td>
    <?php echo endfor; ?>
        <td><?php echo $page_links; ?></td>