Archive for the ‘Core PHP’ Category


How to create recurring payment profile in cakephp for paypal payment pro?

How to create recurring payment profile in cakephp for paypal payment pro..

I have created the paypal component in my component..

Please help me

Thanks…

e-Shop Recurring Payment Plugin

Hii Friends/Webmasters,

I have seen few question over web “Can eShop handle Recurring Billing through PayPal?”. Yes ofcourse it can handle here is the solution in face of plugin :)

As i am big fan of bloging sites, i have read lots of things regarding eshop. I have seen developers/webmasters love the eshop plugin.

Here i again with one new solution for your shopping site that you require :) Guess… Hmmm… Yeah Its “e-Shop Recurring Payment”.

I have completed the first version of e-Shop Recurring payment.

First of all i would like to describe your what is “Recurring Payment”.

Recurring payments are an option that allows your customers to make Visa card payments to you automatically at regular intervals. They can be used in a variety of situations, from monthly subscriptions and leasing arrangements to paying electricity and telephone bills.

Recurring payments mean that customers do not have to worry about remembering to make their payment each time it is due, while you provide better service, receive your payments regularly and save valuable time.

How it works with e-Shop ?
You just need to download the “e-Shop Recurring Payment” Plugin from the site. Install it using installation wizard of wordpress.. That’s It.

Version Support.
It support latest stable version of e-Shop (3.2)

so if any one is in need for this feature let me know i will do it. You can reach me at sudhirtiwari@tricoreitsolutions.com or fill the contact us form with
subject of “Paypal Pro API Plugin for eShop” and your suggations on message part.

You can see the below screencasts that i will provide you for admin settings and user-end setting.
Admin Side User Interface:

e-Shop Recurring Payment Plugin

e-Shop Recurring Payment Plugin

Front Side User Interface:

eshop recurring payment plugin wordpress

eshop recurring payment plugin wordpress

Paypal Pro API Plugin for eShop

I have got lots of request for integration of eshop with paypal pro API..

Clients are asking for same solution but their wording are different….
###1
I would like someone to modify the php for eshop’s paypal gateway so that customers do not leave my site when checking out.

###2
I need a Paypal Pro merchant gateway plugin for eShop. eShop currently offers a standard paypal gateway but does not have settings/option for the Paypal API direct pay. I am aware other shopping carts offer this (like wp ecommerce) but I like the eShop interface and functions.

I would very much like it written as a plugin for eShop.

WordPress version: 3.0.4
eShop version: 6.0.2

etc….

Finally, I desire to add this feature to eShop wordpress plugin..
You can see the demo at my given demo url.
Demo URL : http://www.techphpexpert.com/projects/eshop/

It was great to customize this plugin as its great achievement and everyone is in need of this…..

Currenltly i have customized “eShop” plugin for developers it might be easy to integrate my customization but may be not so easy for webmaster to do this job.

so if any one is in need for this feature let me know i will do it. You can reach me at sudhirsoft01@gmail.com or fill the contact us form with
subject of “Paypal Pro API Plugin for eShop” and your suggations on message part.

You can see the below screencasts that i will provide you for admin settings and user-end setting.
Admin Side User Interface:

Front Side Paypal Pro checkout option:

Insert Your Recent Comments from Facebook to Database

The sample is for scraping data from Facebook home page. Once you will pass your username and password in variables  i have declared in file and execute the code you will get your home page of Facebook.

Here php code will pass the variables by POST method to https://login.facebook.com/login.php page and login into facebook account then other curl call will call my home page to get the home page HTML.

I have written code of how i am scrapping data by DOM Parser.

<?PHP
$first_name = 'First Name';
$login_email = 'facebookloginemail';
$login_pass = 'password';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://login.facebook.com/login.php?m&next=http%3A%2F%2Fm.facebook.com%2Fhome.php');
curl_setopt($ch, CURLOPT_POSTFIELDS,'email='.urlencode($login_email).'&pass='.urlencode($login_pass).'&login=Login');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_COOKIEJAR, "my_cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "my_cookies.txt");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3");
curl_exec($ch);

curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_URL, 'http://m.facebook.com/home.php');
$page = curl_exec($ch);

/*
Here it will print the facebook home page with your recent updates
*/

echo $page;

// Parse the HTML information and return the results.
$dom = new DOMDocument();
@$dom->loadHtml($page);

$xpath = new DOMXPath($dom);

// Get a list of articles from the section page

$articleList = $xpath->query("*/div[@id='m_stream_stories']");
print_r($articleList);

// Add each articles url to the Articles array
// This way we can scrap any part of data of any sites.

$articles = array();
foreach ($articleList as $item){
	$articles[] = array(
								'url' => $item->getElementsByTagName('a')->item(0)->getAttribute('href')
					   );
}

print_r($articles);

// Here we can loop for the article array and insert it into database.
?>

If you have any trouble in getting it work let me know i will help you.

Update Your Facebook Status By PHP Script

Hey would you like to update your facebook status, but don’t want to go to facebook.com, login, and finally being able to update your status?
Then Do one thing simply save the following code on your server, define the variables and Rock :)

<?PHP
/*******************************
*	Facebook Status Updater
*	Christian Flickinger
*	http://nexdot.net/blog
*	April 20, 2007
*******************************/

$status = 'YOUR_STATUS';
$first_name = 'YOUR_FIRST_NAME';
$login_email = 'YOUR_LOGIN_EMAIL';
$login_pass = 'YOUR_PASSWORD';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://login.facebook.com/login.php?m&next=http%3A%2F%2Fm.facebook.com%2Fhome.php');
curl_setopt($ch, CURLOPT_POSTFIELDS,'email='.urlencode($login_email).'&pass='.urlencode($login_pass).'&login=Login');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_COOKIEJAR, "my_cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "my_cookies.txt");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3");
curl_exec($ch);

curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_URL, 'http://m.facebook.com/home.php');
$page = curl_exec($ch);

curl_setopt($ch, CURLOPT_POST, 1);
preg_match('/name="post_form_id" value="(.*)" \/>'.ucfirst($first_name).'/', $page, $form_id);
curl_setopt($ch, CURLOPT_POSTFIELDS,'post_form_id='.$form_id[1].'&status='.urlencode($status).'&update=Update');
curl_setopt($ch, CURLOPT_URL, 'http://m.facebook.com/home.php');
curl_exec($ch);
?>

source : http://codesnippets.joyent.com/posts/show/1204

Get Safe File Name

This function come up with a function that does a good job of sanitizing certain strings so that they are safe to use in the URL (like a post slug) and also safe to use as file names. For example, when someone uploads a file I want to make sure that I remove all dangerous characters from the name.

 function filename_safe($filename) {
     $temp = $filename;
     // Lower case
     $temp = strtolower($temp);
     // Replace spaces with a '_'
     $temp = str_replace(" ", "_", $temp);
     // Loop through string
     $result = '';
     for ($i=0; $i<strlen($temp); $i++) {
         if (preg_match('([0-9]|[a-z]|_)', $temp[$i])) {
             $result = $result . $temp[$i];
         }
     }
     // Return filename
     return $result;
 }

Let me know if you have any queries in using the functions.

Uploading file by PHP Code

Let’s start by creating the html file form:

Files are uploaded from the browser using an input tag, with the type parameter set to “file”. This is supported by all browsers currently available on the market.

The most important thing is to set the ENCTYPE attribute of the form to “multipart/form-data” and set the form’s action to the file upload page. The file upload page will handle the actual file uploading.
html file : upload.html

 <form name="frmupload" id="frmupload" method="post" action="/upload.php" enctype="multipart/form-data">
  <fieldset>
  <legend>File upload:</legend>
  <table>
  <tr>
	<td>
	  <label for="file">File:</label>
	</td>
	<td>
	  <input name="vFile" type="file" id="vFile" />
	</td>
  </tr>
  </table>
  <input type="submit" name="upload" value="Upload" />
  </fieldset>
</form>

Now first create the upload script:
In PHP, uploaded files are accessed via the $_FILES array:

* $_FILES["file"]["name"]: The original filename on the client’s machine.
* $_FILES['file']['type']: The mime type of the file.
* $_FILES['file']['size']: The size, in bytes, of the uploaded file.
* $_FILES['file']['tmp_name']: The temporary filename of the file in which the uploaded file was stored on the server.

Here i have created one function so we will call this in our upload.php it will makes easy to upload , optimize the code and make the code reusable.

php script file : upload.php

<?php
$imagepath='';		// Make Sure you have set the permission of folder in which you are uploading files.
$image= $_FILES['file']['tmp_name'];
$image_name= $_FILES['file']['name'];
$prefix=''; 	// Optional
$vaildext= "gif,jpg,jpeg,bmp,PNG,JPG,JPEG,GIF,BMP,png"; 

$output = fileupload($imagepath , $image , $image_name , $prefix , $vaildext);

fileupload($imagepath,$image,$image_name,$prefix='', $vaildExt= "gif,jpg,jpeg,bmp,PNG,JPG,JPEG,GIF,BMP,png");
 function fileupload($imagepath,$image,$image_name,$prefix='', $vaildext= "gif,jpg,jpeg,bmp,PNG,JPG,JPEG,GIF,BMP,png")
	{

	   $msg="";
	   if(!empty($image_name) and is_file($image) )
		{
			$tmp=explode(".",$image_name);
			for($i=0;$i<count($tmp)-1;$i++)
			{
				$tmp1[]=$tmp[$i];
			}
			$file=implode("_",$tmp1);
			$ext=$tmp[count($tmp)-1];

			$vaildext_arr = explode(",", strtoupper($vaildext));
			if(in_array(strtoupper($ext), $vaildext_arr))
			{
				$imagefile=$prefix.$file."_".date("YmdHis").".".$ext;
				$ftppath1 = $imagepath.$imagefile;
				if(!copy($image, $ftppath1))
				{
					$imagefile = '';
					$msg="Failed to Upload files !!";
				}
				else
					$msg="File uploaded successfully !!";
			}
			else
			{
				$imagefile = '';
				$msg="Extension Is Not Valid, please use mentioned extesions only $vaildExt !!!";
			}
		}
		$ret[0] = $imagefile;
		$ret[1] = $msg;
		return $ret;
	}
?>

Its easy and working :)

Let me know your thoughts if you are facing any problem while uploading files.

PHP Functions to Import/Export CSV data

These two function make it very easy to import and export CSV in PHP.
Documentation
CSVEport()

This function has just one argument – the query that returns the necessary data to be exported.

Example: CSVExport(“SELECT name,username,email,url FROM User WHERE status=1″);
CSVImport()

This will upload a CSV file and import the data into the specified table. This function must have the following arguments…

$table
The name of the table the data must be imported to
$fields
An array of fields that will be used
$csv_fieldname
The name of the CSV file field

Example: CSVImport(“User”, array(‘name’,'username’,'email’,'url’), “csv_file”);
Code
//Get the result of the query as a CSV stream.
//http://www.bin-co.com/php/scripts/csv_import_export/
function CSVExport($query) {
$sql_csv = mysql_query($query) or die(“Error: ” . mysql_error()); //Replace this line with what is appropriate for your DB abstraction layer

header(“Content-type:text/octect-stream”);
header(“Content-Disposition:attachment;filename=data.csv”);
while($row = mysql_fetch_row($sql_csv)) {
print ‘”‘ . stripslashes(implode(‘”,”‘,$row)) . “\”\n”;
}
exit;
}

//Import the contents of a CSV file after uploading it
//http://www.bin-co.com/php/scripts/csv_import_export/
//Aruguments : $table – The name of the table the data must be imported to
// $fields – An array of fields that will be used
// $csv_fieldname – The name of the CSV file field
function CSVImport($table, $fields, $csv_fieldname=’csv’) {
if(!$_FILES[$csv_fieldname]['name']) return;

$handle = fopen($_FILES[$csv_fieldname]['tmp_name'],’r');
if(!$handle) die(‘Cannot open uploaded file.’);

$row_count = 0;
$sql_query = “INSERT INTO $table(“. implode(‘,’,$fields) .”) VALUES(“;

$rows = array();

//Read the file as csv
while (($data = fgetcsv($handle, 1000, “,”)) !== FALSE) {
$row_count++;
foreach($data as $key=>$value) {
$data[$key] = “‘” . addslashes($value) . “‘”;
}
$rows[] = implode(“,”,$data);
}
$sql_query .= implode(“),(“, $rows);
$sql_query .= “)”;
fclose($handle);

if(count($rows)) { //If some recores were found,
//Replace these line with what is appropriate for your DB abstraction layer
mysql_query(“TRUNCATE TABLE $table”) or die(“MySQL Error: ” . mysql_error()); //Delete the existing records
mysql_query($sql_query) or die(“MySQL Error: ” . mysql_error()); // and insert the new ones.

print ‘Successfully imported ‘.$row_count.’ record(s)’;
} else {
print ‘Cannot import data – no records found.’;
}
}

Thanks bin-co.com for writing such infomative Articles

Curl Function in GoDaddy Hosting

I use GoDaddy Hosting for this site. A few days ago I tried to use the curl library. Curl was there – but all my calls timed out. I tried different approaches – but all failed. After some google searches I found out why – GoDaddy is using a proxy server.

So if you are using GoDaddy hosting and what to use curl, you should include these lines in the script…

curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
curl_setopt($ch, CURLOPT_PROXY,”http://64.202.165.130:3128″);

…assuming that $ch is the curl handle.

A full example…

<?php
$url = "http://www.google.com/";

$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
curl_setopt ($ch, CURLOPT_PROXY,"http://64.202.165.130:3128");
curl_setopt ($ch, CURLOPT_TIMEOUT, 120);
$response = curl_exec ($ch);
if(is_int($response)) {
    die("Errors: " . curl_errno($ch) . " : " . curl_error($ch));
}
curl_close ($ch);

print "Remote Site : $url<br /><hr />$response";
?>

Article is taken from bin-co.com.

Using PHP Short Tags

PHP Short Tags refers to ‘

Short tags are considered bad because they are in conflict with XML’s open tag – ‘

This problem can be solved easily – I use this code…

xml

I use the full tag almost all the time. The only exception is that I use . And I am not prepared to give that up.

I follow the MVC pattern in my projects. My PHP framework, iFrame, is an MVC framework. In the template(view) part, there is a lot of usage of such tags. It is more concise and more readable than the alternative…

You tell me – which is better?

I hear that they will be introducing in PHP 6. Until then, I will continue to use .
This article is from bin-co.com. IT was very usefull for me

source:stackoverflow.com
Hire Me
Follow Me!
Search
Most Popular Articles & Pages
Because your vote is Important
Sorry, there are no polls available at the moment.
Categories