Archive

Archive for the ‘PHP’ Category

HTML Webpage to Image – OS Independent

STEPS:

  1. Place the below code in a PHP/HTML file, we will get the thumb image of the given Website
<img src=”http://pagepeeker.com/thumbs.php?size=m&url=http://www.xxxxxx.com/sales-updates&#8221; border=”0″>
  1. The values for size can be: t / s / m / l / x
Advertisements
Categories: PHP

HTML Webpage to Image On Windows – OS Dependent

Note:

  • It works only with Windows OS –  OS Dependent

Steps:

  1. Download and install webthumb-activex-setup.exe from http://www.acasystems.com/en/web-thumb-activex/download.htm
  2. Then paste the below code and save as imageGrap.php

<?php

// Set the save folder

  // [IMPORTANT NOTE]:

  // This sample saves the snapshot to the folder on the work dir of this script.

  // Please make sure the script has the WRITE permission in this folder.

  // You can also set the value to other folder, for example:

  //   $t_strSaveFolder = “c:/temp”;

  $t_strSaveFolder = dirname(__FILE__);

  // Set the image filename

  $t_strLargeImage = $t_strSaveFolder.”/main-thumb.large.png”;

  $t_strSmallImage = $t_strSaveFolder.”/main-thumb.small.png”;

  // Create instance ACAWebThumb.ThumbMaker.

  $t_xMaker = new COM(“ACAWebThumb.ThumbMaker”)

    or die(“Start ACAWebThumb.Maker failed”);

  // Set the URL and start snap

  $t_strURL = ‘http://www.sitename-xxxxx.com/&#8217;; // Site URL

  $t_xMaker->SetURL($t_strURL);

  $t_iRet = $t_xMaker->StartSnap();

  if ( 0 == $t_iRet )

  {

    // snap successful, save webpage to image with full size.

    $t_bRet1 = $t_xMaker->SaveImage($t_strLargeImage);

    // save webpage to thumbnail with 320×240 size

    $t_xMaker->SetThumbSize (320, 240, 0);

    $t_bRet2 = $t_xMaker->SaveImage($t_strSmallImage);

    // show the image online.

    if ( $t_bRet1 && $t_bRet2)

    {

      echo “The snapshot from <a href='”.$t_strURL.”‘ target=_blank>”.$t_strURL.”</a>:”;

      echo “<a href=’main-thumb.large.png’>img src=’main-thumb.small.png’ border=1></a>”;

    }

    else

    {

      echo “ERROR: Can’t save the snapshot to folder “.dirname(__FILE__).”. “;

      echo “Please make sure the script has the WRITE PERMISSION in this folder.”;

    }

  }

  else

    echo “ERROR: Snap from “.$t_strURL.” failed. “;

?>

3. Run the file, we will get the Webpage as image on the same folder.

Categories: PHP

Microsoft (SQL Server 2.0) Drivers for PHP!! using SQLSRV

December 9, 2011 2 comments

STEPS:
1. First we need to install SQL Server Native Client before installing SQL driver for PHP  in your System.
My System Configuration is,
Operating System: Windows 7
System Type: 32-bit Operating System

Install from the http://technet.microsoft.com/en-us/library/cc296170.aspx

— We will get a page titles System Requirements
— We can see a link “Download the X86 package” (If 64-bit OS download X64 package)
— Click the link will download the required file.
— Install it into our system.

2. Download SQLSRV30.EXE OR SQLSRV20.EXE  from http://www.microsoft.com/download/en/details.aspx?id=17308
as per our system requirements.
Check php.ini – If

Compiler MSVC9 (Visual C++ 2008)

Then download php_sqlsrv_53_ts_vc9.dll and include in php.ini as STEP 5.

3.Run the SQLSRV30.EXE OR SQLSRV20.EXE file will ask path for placing the files. Select the PHP extension Directory.
Ex: D:\wamp\bin\php\php5.3.8\ext

4. Also check in php.ini
extension_dir = “D:/wamp/bin/php/php5.3.8/ext/”

5. Include in php.ini as,
extension=php_sqlsrv_53_ts.dll

OR

extension=php_sqlsrv_53_ts_vc6.dll
OR

extension=php_sqlsrv_53_ts_vc9.dll

See the configuration of your system and enable it in php.ini

6. Restart the wampp Server. If not reflected in phpinfo(), restart the sytem.

PHP Code to Connect
=================

<?php//phpinfo();/*Connect to the local server using Windows Authentication and specifythe AdventureWorks database as the database in use. To connect usingSQL Server Authentication, set values for the “UID” and “PWD”attributes in the $connectionInfo parameter. For example:$connectionInfo = array(“UID” => $uid, “PWD” => $pwd, “Database”=>”AdventureWorks”);*/$serverName = “10.18.1.254\SQL2000”;

$connectionInfo = array( “Database”=>”MCMS”, “UID”=>”sa”, “PWD”=>”Defiance123”);

$conn = sqlsrv_connect( $serverName, $connectionInfo);

if( $conn )

{

//echo “Connection established.\n”;

/* Get the product picture for a given product ID. */

$tsql = “SELECT  [BlobData] FROM [MCMS].[dbo].[BlobTable] WHERE BlobId = ?”;

$params = array(24);

/* Execute the query. */

$stmt = sqlsrv_query($conn, $tsql, $params);

if( $stmt === false )

{

echo “Error in statement execution.</br>”;

die( print_r( sqlsrv_errors(), true));

}

/* Retrieve the image as a binary stream. */

$getAsType = SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY);

if ( sqlsrv_fetch( $stmt ) )

{

$image = sqlsrv_get_field( $stmt, 0, $getAsType);

fpassthru($image);

}

else

{

echo “Error in retrieving data.</br>”;

die(print_r( sqlsrv_errors(), true));

}

/* Free the statement and connectin resources. */

sqlsrv_free_stmt( $stmt );

sqlsrv_close( $conn );

}

else

{

echo “Connection could not be established.\n”;

die( print_r( sqlsrv_errors(), true));

}

?>

Categories: PHP, SQL Server

Microsoft SQL Server ODBC Driver Configuration

Steps:
1. Click Control Panel -> All Control Panel Items -> Administrative Tools -> Data Sources (ODBC)

Click Data Sources (ODBC)

Click Data Sources (ODBC)

2. Opens the ODBC Data Source Administrator Pop-up.

3. Select the User DSN -> Click the ADD button to add new DSN

Click the ADD Button

Click the ADD Button

4. Opens a Create New Data Source Pop-up. Select SQL Server and click Finish.

5. Now opens another Pop-up for Database Connection
6. Enter Name, Description for the connection.
7. In SERVER: field provide the server name/ IP and Instance Name

Ex:   10.10.10.20/SQL2005

SQLExpress/SQL2005

Click Next

Click Next

8. Click Next will ask for DB Mapping.

Check the Change the default database to.

In the Change the default database to box, use the pull down list to select the SQL database name that you created using SQL SERVER 2005 MANAGEMENT STUDIO.

Select the required DB.

Select the reruired DB

Select the reruired DB

9. Check Use ANSI quoted identifiers.

Check Use ANSI nulls, paddings and warnings.

   Click Next.

10.  Select Use regional settings…… and click Finish.

11. Click the Test Data Source and Test it.

12. We will get the following successful message dialog box.

13.   Select OK 3 times (one for each dialog box) to exit ODBC configuration.

If it did not Test Successfully.

Try these steps:

–  If the SQL Server is a remote node, verify that TCP port 1433 is open on the SQL Server Node (i.e. check any firewalls or Windows Firewall).

–  Verify the SA Login Password or whatever Login ID you used to configure this DSN.

– Verify the Database name.

– Verify that SQL Server is running.

13. Now we will get the connection Name in the User DSN.

We can see the created DSN name here

We can see the created DSN name here

10. Thats It. Connection has been successfully created for SQL Server through ODBC

We will see how we can access through PHP,

<?php/*

PHP MSSQL Example

Replace data_source_name with the name of your data source.

Replace database_username and database_password

with the SQL Server database username and password.

*/

$data_source=”Driver={SQL Server};Server=10.10.10.20\SQL2005;Database=Name of the DB;”;

$user=’sa’; // Username of the SQL server

$password=’Xxxxxx456′; // Password of the SQL server

// Connect to the data source and get a handle for that connection.

$conn=odbc_connect($data_source,$user,$password);

if($conn)

echo ‘success’;

else

echo ‘failed’;

?>

Categories: PHP, SQL Server

Tweet the content into Twitter

Following steps to create twitter apps In CakePHP :

 

Step 1 : Create a twitter A/C

Step 2 : CURL Must be enabled in your server

Step 3 : Log in to twitter A/C to create an API

a. https://dev.twitter.com/user/login?destination=home

b. Click username on top menu you have one sub menu named My applications

c. Click My application menu

d. Click Create a new application

e. Fill up the application details

f. Callback URL must have .php extenstion

g. Website must be a valid website. we can give our localhost url also

h. Callback URL means after verification of username and password the page redirect into which page

i. click the submit you get the API informations.

j. Under Details->OAuth settings we get Consumer key,Consumer secret and etc.,

 

Step 4 : Go ot Setting Tab in your apps, in Application type you must select the Read and Write or Read, Write and Access direct messages for your apps.

Step 5 : Download the twitter API from online

a. Go to http://www.jaisenmathai.com/articles/twitter-php-sign-in.html and click the link for available for download

b. UnZIP the downloaded package, place the library files into app/vendors/ folder create on folder twitter inside this folder create twitter.php file

c. In twitter.php we include the library files

include ‘EpiCurl.php’;

include ‘EpiOAuth.php’;

include ‘EpiTwitter.php’;

d. In app_controller top we include the following line, App::import(‘Vendor’, ‘twitter/twitter’);

e. Declare these variable as globally

var $consumer_key = ”;

var $consumer_secret = ”;

f. Create an Object for

$twitterObj = new EpiTwitter($this->consumer_key, $this->consumer_secret);

$twitterObj->getAuthenticateUrl() get the login url if user not login than

check whether session $this -> Session -> read(“oauth_token”) exists or not if its not exists than

$twitterObj = new EpiTwitter($this->consumer_key, $this->consumer_secret);

 

Object to connect the twitter API

$twitterObj->setToken($_GET[‘oauth_token’]);

 

twitter return a access token

$token = $twitterObj->getAccessToken();

 

$twitterObj->setToken($token->oauth_token, $token->oauth_token_secret);

set the Token into twitter object, the token is valid than we create a session for that token and secret

// save to cookies

if(isset($_GET[‘oauth_token’])){

$this -> Session -> write(“oauth_token”, $token->oauth_token);

$this -> Session -> write(“oauth_token_secret”, $token->oauth_token_secret);

}

 

$twitterInfo= $twitterObj->get_accountVerify_credentials();

 

Finally we get the twiter user A/C credentials

 

Check one more condition for session exists $this -> Session -> read(“oauth_token”). If its exists than, we create a Object for $twitterObj = new EpiTwitter($this->consumer_key, $this->consumer_secret, $this -> Session -> read(“oauth_token”), $this -> Session -> read(“oauth_token_secret”));

$twitterInfo= $twitterObj->get_accountVerify_credentials();

Now we get the user credentials.

Step 5 : To post content in your twitter A/C the following scripts used to post it

$msg = ‘The message which one you want for it’;

$update_status = $twitterObj->post_statusesUpdate(array(‘status’ => $msg));

 

$temp = $update_status->response;

// Update the status of the twitter object post the conetent and publish it

 

Step 6 : When user can logout we destroy the session.

Categories: CakePHP, PHP

Twitter Integration

Following steps to create twitter apps In CakePHP :

Step1 : Create a twitter A/C

Step2 : CURL Must be enabled in your server

Step3 : Log in to twitter A/C to create an API

a. https://dev.twitter.com/user/login?destination=home

b. Click username on top menu you have one sub menu named My applications

c. Click My application menu

d. Click Create a new application

e. Fill up the application details

f. Callback URL must have .php extenstion

g. Website must be a valid website. we can give our localhost url also

h. Callback URL means after verification of username and password the page redirect into which page

i. click the submit you get the API informations.

j. Under Details->OAuth settings we get Consumer key,Consumer secret and etc.,

Step4 : Download the twitter API from online

a. Go to http://www.jaisenmathai.com/articles/twitter-php-sign-in.html and click the link for available for download

b. UnZIP the downloaded package, place the librarie files into app/vendors/ folder create on folder twitter inside this folder create twitter.php file

c. In twitter.php we include the library files

include ‘EpiCurl.php’;

include ‘EpiOAuth.php’;

include ‘EpiTwitter.php’;

d. In app_controller top we include the following line, App::import(‘Vendor’, ‘twitter/twitter’);

e. Declare these variable as globally

var $consumer_key = ”;

var $consumer_secret = ”;

f. Create an Object for

$twitterObj = new EpiTwitter($this->consumer_key, $this->consumer_secret);

$twitterObj->getAuthenticateUrl() get the login url if user not login than

check whether session $this -> Session -> read(“oauth_token”) exists or not if its not exists than

$twitterObj = new EpiTwitter($this->consumer_key, $this->consumer_secret);

Object to connect the twitter API

$twitterObj->setToken($_GET[‘oauth_token’]);

twitter return a access token

$token = $twitterObj->getAccessToken();

$twitterObj->setToken($token->oauth_token, $token->oauth_token_secret);

set the Token into twitter object, the token is valid than we create a session for that token and secret

// save to cookies

if(isset($_GET[‘oauth_token’])){

$this -> Session -> write(“oauth_token”, $token->oauth_token);

$this -> Session -> write(“oauth_token_secret”, $token->oauth_token_secret);

}

$twitterInfo= $twitterObj->get_accountVerify_credentials();

Finally we get the twiter user A/C credentials

Check one more condition for session exists $this -> Session -> read(“oauth_token”). If its exists than, we create a Object for $twitterObj = new EpiTwitter($this->consumer_key, $this->consumer_secret, $this -> Session -> read(“oauth_token”), $this -> Session -> read(“oauth_token_secret”));

$twitterInfo= $twitterObj->get_accountVerify_credentials();

Now we get the user credentials.

Step 5 : When user can logout we destroy the session.

Categories: CakePHP, PHP

Facebook integration

Following steps to create face book apps In CakePHP :

Step 1 : Create a Facebook A/C

Step 2 : Create an API from the developer face book Apps section

a. https://www.facebook.com/developers/apps.php go to this URL

b. Click the create new App Button

c. Fill the App Display Name and App Namespace text boxes

d. click the Website tab and register your site name

e. Now you get an API Key and security codes.

Step 3 : Collect the Facebook PHP API Script from online

a. Go to https://github.com/facebook/php-sdk

b. Download the PHP Facebook API script

c. Unzip into your local server or demo server

d. Run examples/example.php file, it show how to execute the Facebook API script

Step 4 : Put all library files inside the app/vendors folder, folder name must be facebook/facebook.php, facebook.php file is a class file which have the all functions

Step5 : In AppController you import the facebook classes like App::import(‘Vendor’, ‘facebook/facebook’);

Step 6 : In beforeFilter() function, write the script

$facebook = new Facebook(array(

‘appId’ => ‘263138650385665’,

‘secret’ => ‘9c21ee36a91a81787ff5db8368926ee5’,

));

the appid and secret is which we generate from the step 2.

Step 7 : If user login with facebook then we get the username and email-id and etc from their facebook a/c. Assign these values globally

Step 8 : In users_controller check whether facebook user variable exists or not, if its exists than we create a session name for user authentication

Step 9 : Now we redirect the page into mainpage.

Step 10 : In bas_facebook.php file go to line no 496

function public function getLogoutUrl($params=array(),$url) { }

change the ‘next’ => $this->getCurrentUrl(), into which you want for logout page.

Categories: CakePHP, PHP