Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Saturday, February 4, 2012

Paypal IPN in PHP


// PHP 4.1

// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';

foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}

// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);

// assign posted variables to local variables
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];

if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
// check the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
// check that payment_amount/payment_currency are correct
// process payment
}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
}
}
fclose ($fp);
}
?>

Tuesday, August 31, 2010

Queued Photo Uploader with J query

Java Script Code For that Tool 


window.addEvent('domready', function() { // wait for the content
 
 // our uploader instance 
 
 var up = new FancyUpload2($('demo-status'), $('demo-list'), { // options object
  // we console.log infos, remove that in production!!
  verbose: true,
 
  // url is read from the form, so you just have to change one place
  url: $('form-demo').action,
 
  // path to the SWF file
  path: '../../source/Swiff.Uploader.swf',
 
  // remove that line to select all files, or edit it, add more items
  typeFilter: {
   'Images (*.jpg, *.jpeg, *.gif, *.png)': '*.jpg; *.jpeg; *.gif; *.png'
  },
 
  // this is our browse button, *target* is overlayed with the Flash movie
  target: 'demo-browse',
 
  // graceful degradation, onLoad is only called if all went well with Flash
  onLoad: function() {
   $('demo-status').removeClass('hide'); // we show the actual UI
   $('demo-fallback').destroy(); // ... and hide the plain form
 
   // We relay the interactions with the overlayed flash to the link
   this.target.addEvents({
    click: function() {
     return false;
    },
    mouseenter: function() {
     this.addClass('hover');
    },
    mouseleave: function() {
     this.removeClass('hover');
     this.blur();
    },
    mousedown: function() {
     this.focus();
    }
   });
 
   // Interactions for the 2 other buttons
 
   $('demo-clear').addEvent('click', function() {
    up.remove(); // remove all files
    return false;
   });
 
   $('demo-upload').addEvent('click', function() {
    up.start(); // start upload
    return false;
   });
  },
 
  // Edit the following lines, it is your custom event handling
 
  /**
   * Is called when files were not added, "files" is an array of invalid File classes.
   * 
   * This example creates a list of error elements directly in the file list, which
   * hide on click.
   */ 
  onSelectFail: function(files) {
   files.each(function(file) {
    new Element('li', {
     'class': 'validation-error',
     html: file.validationErrorMessage || file.validationError,
     title: MooTools.lang.get('FancyUpload', 'removeTitle'),
     events: {
      click: function() {
       this.destroy();
      }
     }
    }).inject(this.list, 'top');
   }, this);
  },
 
  /**
   * This one was directly in FancyUpload2 before, the event makes it
   * easier for you, to add your own response handling (you probably want
   * to send something else than JSON or different items).
   */
  onFileSuccess: function(file, response) {
   var json = new Hash(JSON.decode(response, true) || {});
 
   if (json.get('status') == '1') {
    file.element.addClass('file-success');
    file.info.set('html', '<strong>Image was uploaded:</strong> ' + json.get('width') + ' x ' + json.get('height') + 'px, <em>' + json.get('mime') + '</em>)');
   } else {
    file.element.addClass('file-failed');
    file.info.set('html', '<strong>An error occured:</strong> ' + (json.get('error') ? (json.get('error') + ' #' + json.get('code')) : response));
   }
  },
 
  /**
   * onFail is called when the Flash movie got bashed by some browser plugin
   * like Adblock or Flashblock.
   */
  onFail: function(error) {
   switch (error) {
    case 'hidden': // works after enabling the movie and clicking refresh
     alert('To enable the embedded uploader, unblock it in your browser and refresh (see Adblock).');
     break;
    case 'blocked': // This no *full* fail, it works after the user clicks the button
     alert('To enable the embedded uploader, enable the blocked Flash movie (see Flashblock).');
     break;
    case 'empty': // Oh oh, wrong path
     alert('A required file was not found, please be patient and we fix this.');
     break;
    case 'flash': // no flash 9+ :(
     alert('To enable the embedded uploader, install the latest Adobe Flash plugin.')
   }
  }
 
 });
 
});
 
Html Code :
 
<form action="../script.php" method="post" enctype="multipart/form-data" id="form-demo">
 
 <fieldset id="demo-fallback">
  <legend>File Upload</legend>
  <p>
   This form is just an example fallback for the unobtrusive behaviour of FancyUpload.
   If this part is not changed, something must be wrong with your code.
  </p>
  <label for="demo-photoupload">
   Upload a Photo:
   <input type="file" name="Filedata" />
  </label>
 </fieldset>
 
 <div id="demo-status" class="hide">
  <p>
   <a href="#" id="demo-browse">Browse Files</a> |
   <a href="#" id="demo-clear">Clear List</a> |
   <a href="#" id="demo-upload">Start Upload</a>
  </p>
  <div>
   <strong class="overall-title"></strong><br />
   <img src="../../assets/progress-bar/bar.gif" class="progress overall-progress" />
  </div>
  <div>
   <strong class="current-title"></strong><br />
   <img src="../../assets/progress-bar/bar.gif" class="progress current-progress" />
  </div>
  <div class="current-text"></div>
 </div>
 
 <ul id="demo-list"></ul>
 
</form> 
 
Get Source File And more detail Here : http://digitarald.de/project/fancyupload/3-0/showcase/photoqueue/ 
 

Wednesday, March 17, 2010

PHP - Necessary Setup

PHP - Necessary Setup
  • A web hosting account that supports the use of PHP web pages and grants you access to MySQL databases. If you do not have a host, but are interested in signing up for one, we recommend that you first read our Web Host Guide to educate yourself about web hosting and avoid getting ripped off.
  • Have PHP and MySQL installed on your own computer. Read this lesson thorougly for more information on installing PHP.
Although MySQL is not absolutely necessary to use PHP, MySQL and PHP are wonderful complements to one another and some topics covered in this tutorial will require that you have MySQL access.

Installing PHP

For those who are experienced enough to do this yourself, simply head over to PHP.net - Downloads and download the most recent version of PHP.
However, if you are like most of us, you will most likely want to follow a guide to installing PHP onto your computer. These guides are kindly provided by PHP.net based on the operating system that you are using.
  • PHP - Windows - Windows Installation Guide
  • PHP - Mac - Mac Installation Guide
  • PHP - Linux - Linux Installation Guide

Installing MySQL

Visit MySQL's MySQL Installation Guide for help on installing MySQL. 


 

Example using control structures and functions

<?phpif (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) {
    echo 
'You are using Internet Explorer.<br />';
}
?>
 
Here we introduce a couple of new concepts. We have an if statement. If you are familiar with the basic syntax used by the C language, this should look logical to you. Otherwise, you should probably pick up an introductory PHP book and read the first couple of chapters, or read the Language Reference part of the manual.
The second concept we introduced was the strpos() function call. strpos() is a function built into PHP which searches a string for another string. In this case we are looking for 'MSIE' (so-called needle) inside $_SERVER['HTTP_USER_AGENT'] (so-called haystack). If the needle is found inside the haystack, the function returns the position of the needle relative to the start of the haystack. Otherwise, it returns FALSE. If it does not return FALSE, the if expression evaluates to TRUE and the code within its {braces} is executed. Otherwise, the code is not run. Feel free to create similar examples, with if, else, and other functions such as strtoupper() and strlen(). Each related manual page contains examples too. If you are unsure how to use functions, you will want to read both the manual page on how to read a function definition and the section about PHP functions.
 

Printing a variable (Array element)

<?phpecho $_SERVER['HTTP_USER_AGENT'];?>
 
There are many types of variables available in PHP. In the above example we printed an Array element. Arrays can be very useful.
$_SERVER is just one variable that PHP automatically makes available to you. A list can be seen in the Reserved Variables section of the manual or you can get a complete list of them by looking at the output of the phpinfo() function used in the example in the previous section.
 

Example of PHP "Hello word"

Our first PHP script: hello.php

<html>
 <head>
  <title>PHP Test</title>
 </head>
 <body>
 <?php echo '<p>Hello World</p>'?>
 </body>
</html>

When developing locally this URL will be something like http://localhost/hello.php

<html>
 <head>
  <title>PHP Test</title>
 </head>
 <body>
 <p>Hello World</p>
 </body>
</html>
  

PHP requirement

Let us say you want to save precious bandwidth and develop locally for php. In this case, you will want to install a web server, such as » Apache, and of course » PHP. You will most likely want to install a database as well, such as » MySQL.