Friday, February 22, 2013

How to post my dyamic product to Facebook Wall post?

We can create an Facebook APP id and its secret code. Now You can use this below code for post the dynamic products to Facebook Wall post..

                            /*************** Facebook wall post ***************/
                            require "facebook/src/facebook.php";
                            $app_id = "00000000000000000";
                            $app_secret = "000000000000000000000000000000000";
                           
                            // Init facebook api.
                            $facebook1 = new Facebook(array(
                                    'appId' => $app_id,
                                    'secret' => $app_secret,
                                    'cookie' => true
                            ));
                           
                            $user = $facebook1->getUser();
                            if ($user)
                            {
                                try
                                {
                                    $user_profile = $facebook1->api('/me?fields=id,email');
                                    $email=$user_profile['email'];
                                    $id=$user_profile['id'];
                                   
                                    $post_url = '/me/feed';
                                    $msg_body = array(
                                                'message' => $product_type.": ".$_SESSION['list_product_title1'],
                                                'link' => $SITE_URL."post_list.php?uid=".$tmpid_list."&post=".md5($tmpid_list),
                                                'name' => $_SESSION['list_product_title1'],
                                                'caption' => $_SESSION['list_product_title1']
                                            );
                                    if ($user) {
                                      try {
                                            $postResult = $facebook1->api($post_url, 'post', $msg_body );
                                          }
                                      catch (FacebookApiException $e) {
                                            echo $e->getMessage();
                                        }
                                    }
                                }
                                catch(FacebookApiException $e){
                                    $facebook1->destroySession();
                                }
                            }
                            /*************** Facebook wall post ***************/

Friday, February 8, 2013

Multiple Facebook like button in a single page / URL using PHP

Follow the below steps one by one..

1) In Details of a product page :

Inside the head tag:

<meta property="og:title" content="<?=$product_title?>"/>
<meta property="og:type" content="product"/>
<meta property="og:url" content="<?=$SITE_URL?>product_detail.php?productid=<?=$product_id?>"/>
<? if($upload_image != '') { ?>
<meta property="og:image" content="<?=$SITE_URL?>products/thumb/<?=$upload_image?>"/>
<? } else { ?>
<meta property="og:image" content="<?=$SITE_URL?>products/original/default.jpg"/>
<? } ?>
<meta property="og:site_name" content="<?=$SITE_URL?>"/>
<meta property="fb:admins" content="0000000000"/> <!-- 0000000000 - Replace with your Facebook profile ID (FBID) -->
<meta property="og:description" content="<?=$product_desc?>"/>

Inside the body tag (In required place):

<fb:like href="<?=$SITE_URL?>product_detail.php?productid=<?=$product_id?>" layout="button_count" show_faces="false" width="240" height="40" action="like" colorscheme="light"></fb:like>

2) In the List page (All products listed with short description and details page link) :


Inside the body tag (In required place):  


<fb:like style="top:-3px" colorscheme="light" action="like" show_faces="false" layout="button_count" href="<?=$SITE_URL?>product_detail.php?productid=<?=$product_id?>" fb-xfbml-state="rendered" class="fb_edge_widget_with_comment fb_iframe_widget"><span style="height: 20px; width: 74px;"><iframe scrolling="no" id="f3b003f3c8bca78" name="f3b36b728edb6bc" style="border: medium none; overflow: hidden; height: 20px; width: 74px;" title="Like this content on Facebook." class="fb_ltr" src="http://www.facebook.com/plugins/like.php?api_key=000000000000000&amp;locale=en_US&amp;sdk=joey&amp;channel_url=<?=$SITE_URL?>product_detail.php?productid=<?=$product_id?>&amp;href=<?=$SITE_URL?>product_detail.php?productid=<?=$product_id?>&amp;node_type=link&amp;width=90&amp;layout=button_count&amp;colorscheme=light&amp;action=like&amp;show_faces=false&amp;extended_social_context=false"></iframe></span></fb:like>

<!--000000000000000 - Replace with your Facebook APPID. First you must create Facebook Apps. Then they given the Facebook APPID-->

After that do the required changes like SITE_URL, product_title, upload_image, product_desc, product_id, productid, AppID, FBID etc.

Now Your website is ready for use. :-)

How to find my Facebook ID (FBID)

Find my Facebook ID (FBID)

Open a browser tab and paste the below URL,

https://developers.facebook.com/tools/explorer?method=GET&path=YOURNAME

Here replace YOURNAME with facebook profile name and give enter

It will display the below content

{
  "id": "111111111",
  "name": "YOUR NAME",
  "first_name": "FIRST NAME",
  "middle_name": "MIDDLE NAME",
  "last_name": "LAST NAME",
  "link": "https://www.facebook.com/YOURNAME",
  "username": "YOURNAME",
  "gender": "male",
  "locale": "en_GB"
}

Tuesday, February 5, 2013

PHP Password Protection By Encryption

The Encryption

Say a user signs up to your site and he/she enters the password “iLoveDogs”, the way you would encrypt the password would be the following.
<?php

 $password="iLoveDogs";

$salt="onlyIKnowThis";

$encryptedPassword=crypt($password,$salt);

// SQL Stuff: save $encryptedPassword to database here
?>

See If Passwords Match

And the way you would check to see if the passwords match would be this:
<?php

 $password="iLoveDogs";

$salt="onlyIKnowThis";

$encryptedPassword=crypt($password,$salt);

// SQL Stuff: extract password from database and save to $passwordFromDatabase here
if($passwordFromDatabase==$encryptedPassword)
{
   // passwords match
}
else
{
  // passwords do not match
}
?>

What Is Salt?

You are probably wondering how we ever got minerals mixed up with web development. The salt servers as an extra "condiment" to encrypt the password even further, think of it as a door having two keys holes one of which is the salt in this case.

If somebody gained access to the passwords in the database and figured out the encrypt() algorithm they would still have to know the salt, so keep it in a safe place!
For more info on how crypt() works check out its page.

How To Send Text Messages From Google Voice With PHP

I found this neat PHP class that you can use to send text messages to any phone number from your google voice account. 

<?php
// GoogleVoice(EMAIL, PASSWORD)
$gv = new GoogleVoice('youremail@gmail.com', 'yourpassword');
// Sends an SMS. send_sms(NUMBER, MESSAGE)
echo $gv->send_sms('+91xxxxxxxxxx', 'Test Message');
// Gets all the sms
// get_sms() - returns all the sms
// get_sms(true) - returns all the unread sms
echo $gv->get_sms();
 
/**
  * Google Voice API Wrapper
  * 
  * new GoogleVoice(EMAIL, PASSWORD)
  * send_sms(NUMBER, MESSAGE)
  * get_sms()
  * get_sms(true) - unread
  *
  * @author Artem Kalinchuk
**/
 
Class GoogleVoice {
 /**
   * Modify this
 **/
 var $account_type = 'GOOGLE';  // The Google account type
 var $service = 'grandcentral';  // Service for Google Voice is grandcentral (it may change)
 var $source = '';    // The host of your site (for logging purposes) 
 // _rnr_se - This can be found in the source code of the inbox page of your Google Voice
 // Simply view the source and search for '_rnr_se'. Should be a string of about 30
 // characters (numbers, letters, and symbols)
 var $_rnr_se = ''; 
 
 /**
   * Do not modify
 **/
 var $url = 'https://www.google.com/'; // Google HTTPS URL
 var $auth;         // The AUTH key
 var $email;        // Users email address
 var $password;       // Users password
 
 function __construct ($email, $password) {
  if ($email)
   $this->email = $email;
  if ($password)
   $this->password = $password;
 
  // Authenticate if the Auth key is empty
  if ($this->auth == '') {
   $this->authenticate();
  }
 }
 
 /**
   * authenticate
   * Authenticates using the email and password.
   * @return Auth Session Key
 **/
 
 function authenticate () {
  $form_data = array();
  $form_data['accountType'] = $this->account_type;
  $form_data['Email'] = $this->email;
  $form_data['Passwd'] = $this->password;
  $form_data['service'] = $this->service;
  $form_data['source'] = $this->source;
 
  $response = $this->transmit($form_data, 'accounts/ClientLogin');
  preg_match("/Auth\=(.*)/", $response, $matches);
 
  if (count($matches) == 0) {
   return $response;
  } else {
   $this->auth = str_replace("Auth=", "", $matches[0]);
   return $this->auth;
  }
 }
 
 /**
   * transmit
   * Transmits the passed in POST data
   * @param $form_data An array of POST fields and values
   * @param $path The path to call
   * @return Response from the server
 **/
 
 function transmit ($form_data, $path, $USE_POST=true) {
  $url = $this->url.$path;
  $fields = array();
 
  foreach ($form_data as $field => $value)
   $fields[] = $field.'='.urlencode($value);
 
  // POST or GET?
  if ($USE_POST) {
   $ch = curl_init($url);
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
   curl_setopt($ch, CURLOPT_POST, count($form_data));
   curl_setopt($ch, CURLOPT_POSTFIELDS, implode('&', $fields));
   curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
   curl_setopt($ch, CURLOPT_HTTPHEADER, array( 
"Content-Type: application/x-www-form-urlencoded", 
"Authorization: GoogleLogin auth=".$this->auth));
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  } else {
   $ch = curl_init($url.'?'.implode('&', $fields));
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
   curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  }
 
  $response = curl_exec($ch);
 
  return $response;
 }
 
 /**
   * send_sms
   * Sends an SMS message
   * @param $phone_number The number to send the SMS message to
   * @param $text The message
   * @return Response from the server (success or fail)
 **/
 
 function send_sms ($phone_number, $text) {
  $form_data = array();
  $form_data['phoneNumber'] = $phone_number;
  $form_data['text'] = $text;
  $form_data['id'] = '';
  $form_data['_rnr_se'] = $this->_rnr_se;
 
  $response = $this->transmit($form_data, 'voice/sms/send/');
 
  return $response;
 }
 
 /**
   * get_sms
   * Gets the HTML of the SMS inbox
   * @param $UNREAD boolean - Show unread or not
   * @return The HTML from the SMS inbox page
 **/
 
 function get_sms($UNREAD=false) {
  $form_data = array();
  $form_data['auth'] = $this->auth;
 
  if ($UNREAD)
   $path = 'voice/inbox/recent/unread/';
  else
   $path = 'voice/inbox/recent/';
 
  $response = $this->transmit($form_data, $path, false);
 
  return $response;
 }
}
?>

Backup huge DB from Server

How to Backup the Huge Database from server.

1) Download Putty from the below URL,

http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

2) Connect Putty with your website details like yourwebsitename.com

3) Follow the below step after login the Putty 

Login as : TTTTTTTTTT

TTTTTTTTTT@websitename.com's password :

Last login........

TTTTTTTTTT@websitename.com [~]# ls
///////////////////////////////////////

//It will list all Folder from the server

///////////////////////////////////////

Last login........

TTTTTTTTTT@websitename.com [~]# mysqldump -u DB_username -p DB_name > public_html/backup/backup_db.sql

Enter password: ______

TTTTTTTTTT@websitename.com [~]# // Now it backup the DB and save this into server with the name 'backup_db.sql' inside backup folder

exit


4) Now it backup the DB and save this into server with the name 'backup_db.sql'

5) After that you can download this from server via FTP or control panel

Image uploading via mobiles using php

Find the following lines

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">



Replace the following lines

<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">


Now it will ready to work in all types of mobiles and as well as all browsers. 
I used this for image uploading via mobile.