Online Pharmacy

online viagra buy generic cialis in brisbane identify cialis Viagra without Perscription cialis buy online viagra lawyers Discount viagra cialis overnight Viagra Propecia low cost viagra where can one buy cialis cialis order from us buy cialis generic what is the price of viagra buy viagra in uk buy cheap cialis generic levitra viagra viagra pharmacy buy cialis in canada Discount Pfizer Viagra cheap generic viagra buy cheap cialis online Cheapest Viagra Price buy viagra mastercard viagra cialis levitra cialis commercial Buy Onlinecom Phentermine Viagra cheapest place to buy viagra online viagra pill cialis buy without prescription buy viagra no prescription buy cialis now top internet cialis web sites cialis mastercard buy cheap cialis in australia order cialis now Viagra Faq visa viagra viagra mastercard female viagra Viagra Tablet mastercard buy viagra cialis pro buy online viagra how does cialis work venta de cialis viagra cialis buy generic cialis from india Viagra Facts about viagra Cialis Viagra Online buy tadalafil cialis best price viagra buy cialis generic online Buy Viagra Now Online buy cheap cialis ipharmacy is cialis better than viagra No Prescription Viagra where to buy cialis where can i buy viagra from Viagra Pushups cialis soft tabs buy low price viagra where to buy viagra cialis vs. viagra buy cialis australia buy viagra paypal Buy Viagra Onlines best place to buy cialis where buy viagra cialis india sildenafil cialis generico what dose cialis does cialis work what is the generic name for cialis viagra cialis compare cialis levitra viagra buy viagra on line buy cialis paypal In Man Uk Viagra sales cialis buy cheap cialis ciales cialis buy discrete buy generic cialis online cialis women viagra from health store order viagra cialis viagra online buy cialis online viagra cheap price viagra Drug Viagra viagra buy maile order cialis cialis compared to viagra buy cialis online no prescription buy cheap viagra cialis visa Between Difference Levitra Viagra buy cialis visa discount viagra online Cheap Generic India Viagra viagra sale buy viagra where cialis and alcohol order cialis cheap buy cialis american express cialis 10mg cialis small packs cheap viagra uk sell viagra to buy cialis mastercard buy cialis buy canada cialis buy cheap purchase uk viagra viagra low cost mastercard viagra buy viagra visa viagra visa Viagra Alternative buy cialis drug online rx buy cialis cialis experience buy viagra line viagra sale online Very Cheap Viagra natural viagra Deer Viagra where can i buy viagra Viagra Online Shop is levitra better than cialis viagra prescription order viagra viagra for woman order cialis on line cialis generic buy discrete buy cialis soft tabs online chea Viagra Discount low cost cialis viagra best buy order cialis online herbal cialis prescription cialis us pharmacy buy viagra without prescription Cialis Generic Levitra Viagra cialis side effects cialis archive newest Viagra Concerns cialis visa cialis online no presription buying generic cialis buy viagra online cheap buy cialis without prescription buy cialis tablets buy viagra usa american express buy viagra viagra cialis generica what stores sell viagra cialis canada cialis order cialis europe viagra buy generic cialis viagra and cialis cheap discount viagra mastercard cialis buy cialis without a prescription Compare Levitra And Viagra cialis uk cialis sales cialis daily buy viagra Canadas Viagra Commercial buy cialis and viagra viagra mastercard viagra visa side effects of cialis Viagra for Women Cheapest Viagra cialis message board overnight cialis cheap cialis where to buy levitra cialis viagra online generic viagra viagra price buycialisonline liquid cialis Viagra Generika where can i buy cialis online viagra cialis phentermine soma sell viagra online Comparison Viagra Levitra Cialis buy cialis with no prescription cialis professional viagra dosage generic cialis soft online cheapest cialis cialis smile blog buy generic cialis viagra online generic cialis soft cheap generic cialis order cialis cialis mastercard Cialis Compare Levitra Viagra daily cialis buy cialis viagra Cheapest Cheap Viagra buy cialis online now Can Women Take Viagra buy uk viagra order cheap cialis generic cialis india buy cialis cheap Viagra Generic Drug Levitra Viagra paypal buy cialis Viagra Dangers cialis buy next day delivery buy cialis no prescription cialis forum buying cialis best price cialis Buy Viagra Order Viagra cialis for women viagra buy viagra cheap viagra alternatives american express buy cialis cialis to buy new zealand buy cialis line where to buy levitra cialis viagra no prescription paypal buy viagra visa cialis buy cheap generic cialis online cialis pricing Pill Viagra which is better cialis or viagra How Does Viagra Work Cialis Super Viagra buy cialis where cialis thanks blog Viagra Or Cialis buy cialis from icos 3cialis Generic Levitra Viagra generic viagra viagra on line Herbal Viagra Wholesale Generic India Viagra cialis on line Buy Cheap Uk Viagra Compare Cialis Levitra Viagra viagra cialis online buy generic viagra buy cialis online cialis online order viagra canada Cialis Comparison Levitra Viagra cheap viagra usa buy cialis doctor online buy cialis mastercard Levitra Or Viagra viagra online order viagra Buy Line Viagra viagra online order guide soft cialis cialis viagra cheap Soft Tab Viagra Sales Viagra cheap viagra cialis dosage propecia cialis viagra book buy cialis guest jill org site viagra online purchase cialis buy buy viagra online where can i buy cialis cialis mail order cheap viagra online viagra usa viagra buy online cialis confusion buy generic cialis in australian pharmacy where buy cialis visa buy viagra buy viagra online inu purchase viagra cialis clock buy viagra uk buy cialis custom hrt Viagra Sale Uk buycialis viagra cialis generic cialis best price viagra cialis cialis generic Sildenafil Viagra pfizer viagra viagra UK buy discount cialis buy cialis cheap in the uk Viagra Buy Viagra cheap cialis sale online Viagra Womans cialis online buy viagra in the uk viagra generic Viagra Online Purchase viagra for sale viagra generic buy Cialis Levitra Viagra cialis cost buy cialis in singapore visa buy cialis buy viagra now viagra side effects order viagra online Generic Viagra Sale Ciscount Viagra Viagra Com buy cialis on line buy viagra in canada viagra dose viagra soft tabs Viagra Lowest Price Viagra In The Water viagra pills buy viagra american express viagra order cialis daily use buy online order viagra order generic cialis discount cialis Effects Of Viagra where to buy viagra on line cheap sale viagra Viagra Onlines prices cialis Viagra Perscription viagra online ordering cialis for order Cheapest Viagra Prices Online Viagra Sale

:: Archive for the 'PHP' Category ::

PHP5 Defensio Class

Posted on November 24th, 2007 in PHP by Greg

Looooong time since I’ve written anything here – about 9 months! This time around I’ve put together a simple PHP5 class for communicating with the Defensio web service. Defensio has an example PHP class, but unfortunately it is PHP4 only and it’s more fun to rewrite it, right?

For those who don’t know about Defensio, it is a web service for determining whether a comment on a blog or message in an application is spam. To use it, you must first register for an API key. Defensio is very similar to the venerable Akismet (see the article I wrote on Akismet) but they provide a couple other features such an indication of the ’spaminess’ of an individual message. Akismet has worked out great for me (123,419 spam comments caught so far!), but I figured it would be good to try out something new as well.

The class is a PHP5 class and the public methods are reasonably well commented. The bottom of this post has a link to a test application and a download of the class/test application. So…the usage of this class is quite straightforward, as shown below:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
require('library/Gregphoto/Defensio.php');
require('library/Gregphoto/Defensio/Adapter/Streams.php);
 
$apiKey = 'mysecretapikey';
$siteUrl = 'http://my.secret.site.url.com';
 
$defensio = new Gregphoto_Defensio($apiKey,$siteUrl);
$defensio->setHttpClient(new Gregphoto_Defensio_Adapter_Streams());
 
$params = array(
	'user-ip' => $_SERVER['REMOTE_ADDR'],
	'article-date' => '2007/11/24',
	'comment-author' => 'Big Bad Spammer',
	'comment-type' => 'comment',
	'comment-content' => 'please click links and buy viagra',
	'comment-author-email' => 'bigbadspammer@annoying.com',
	'comment-author-url' => 'http://www.annoying.com'
);
$result = $defensio->audit_comment($params);
if($result['spam'] == 'true') {
	echo "Comment is spam with a spam score of " . $result['spaminess'];
} else {
	echo "Comment is not spam";
}

A couple key points on usage:

  • Each Gregphoto_Defensio object requires an Http adapter that it will use to make Http POST requests to the Defensio web service. I originally hardcoded it to use the Zend_Http_Client from the Zend Framework, but figured this could discourage people from using it. Then I wrote up a quick adapter to use PHP’s Http Stream Wrappers, but realized that didn’t work on my Dreamhost account, so I added in an extra one for the Curl extension. In theory I should have added a Gregphoto_Defensio_Adapter_Interface class, but I was lazy and didn’t want to add in an extra file.
  • Each Gregphoto_Defensio object can be used to make many requests
  • All of the current Defensio API’s are covered by the class. These are covered by the following methods in the Gregphoto_Defensio class:
    • validate_key
    • announce_article
    • audit_comment
    • report_false_negatives
    • report_false_positives
    • get_stats
  • Each of these methods takes a single parameter, an associative array of options as defined by the Defensio API. Each API also returns an associative array of response parameters. Two static utility methods Gregphoto_Defensio::getActions (returns a list of defensio methods such as ‘validate-key’) and Gregphoto_Defensio::getActionDetails (returns a list of required parameters, optional parameters, and response parameters for a specific Defensio action) are provided in order to get the details of the input and output parameters.

I created a simple test application which can be used to test Gregphoto_Defensio and all of the APIs provided by Defensio.

Download the Gregphoto_Defensio class and the test application


Announcing Gregphoto_Image – a PHP5/GD2 Thumbnail Class

Posted on February 3rd, 2007 in PHP, Web Development by Greg

I put together a simple, lightweight PHP class for generating thumbnail images. The class is compatible with PHP5 and uses the GD2 extension (included by default with PHP5) to create JPEG, PNG, and GIF thumbnails. I’ve setup a Google Code project for it: Gregphoto_Image where you can checkout the source from SVN and file bugs.

The class has the following basic features:

  • Ability to read JPEG, PNG, or GIF images
  • Ability to output JPEG, PNG, or GIF images
  • 4 modes of thumbnail creation
    • MAX_HEIGHT – you specify a maximum height and the dimensions are calculated based off of the height
    • MAX_WIDTH – you specify a maximum width and the dimensions are calculated based off of the width
    • BEST_FIT – you specify a maximum height and width and the dimensions are calculated so that the thumbnail
      is as large as possible without exceeding the maximum height or width
    • EXACT – you specify a maximum height and width and these are directly used. Causes distortion if the
      chosen aspect ratio is different from the aspect ratio of the image
  • Renders/saves images in their input format by default, but allows changing the format. For example, input a GIF but output a PNG
  • Fully documented object oriented code
  • Fluent interface for creating thumbnails with a minimal amount of code

The class is licensed under the MIT license, which basically means it can be used and modified by anyone – for personal or commercial use.

You can Download it from the project page on Google Code. You can view examples of it running on my site – the examples are checked into SVN and can be viewed on the project site. You can also view the docs.

Example usage:

1
2
3
4
5
6
7
require('path/to/Gregphoto_Image.php');
$image = new Gregphoto_Image('path/to/sample/image.jpg');
$image->setMaxHeight(200);
$image->setMaxWidth(200);
$image->setJpegQuality(90);
$image->resize(Gregphoto_Image::BEST_FIT);
$image->showThumbnail();
1
2
$image = new Gregphoto_Image('../images/fan.jpg');
$image->setMaxHeight(200)->setJpegQuality(90)->resize()->showThumbnail();
1
2
3
4
5
6
7
8
require('path/to/Gregphoto_Image.php');
$image = new Gregphoto_Image('path/to/image.jpg');
$image->setMaxHeight(200);
$image->setMaxWidth(200);
$image->setJpegQuality(90);
$image->setOutputType(IMAGETYPE_PNG);
$image->resize(Gregphoto_Image::BEST_FIT);
$image->saveThumbnail('path/to/thumbnail.png');

Enjoy!

Ajax Form Validation

Posted on July 30th, 2006 in PHP, Web Development by Greg

Recently I put together a reusable Ajax form validation component that I’d like to share. It is a JavaScript object that collects the values of all of the elements in a form, sends it for processing to the server, and displays any errors. If there are no errors it submits the form. There are several benefits to this approach

  • Allows you to perform complex validation, such as verifying the uniqueness of a username, or checking something in the database…all without reloading the page
  • Allows you to use the same validation routine for both client-side validation and server-side validation
  • Reduces the amount of client-side code needed for validation

The JavaScript used in my example requires the Prototype library. My example uses PHP to perform the validation – more specifically, I’ve used several components of the Zend Framework (PHP5 only). The example uses:

  • Zend_Controller_* classes including the new RewriteRouter to handle the routing within the application
  • Zend_View to handle the output
  • Zend_View_Helper_* classes to build form elements
  • Zend_Config to read in configuration options
  • Zend_Filter to perform several field validations
  • Zend_Json to serialize PHP variables/objects to JSON objects

Did I need all of this stuff on the server-side to put together a simple form validation example? Heck no, but when I’m experimenting with new stuff I like to use a lot of new components so I can learn more about them and be prepared for when I actually do need to use all of this fire power. I’ve been following the Zend Framework carefully, so I wanted to use some of the stuff I hadn’t used yet – particularly the controller architecture.

The HTML and JavaScript

Ok, back to how this JavaScript is used. It’s actually really quite simple. First, you need to include the JavaScript files for both Prototype and AjaxFormValidator in the head of your HTML document:

1
2
<script src="/ajaxValidate/static/js/prototype.js"></script>
<script src="/ajaxValidate/static/js/ajaxFormValidate.js"></script>

Next, you add an ‘onSubmit’ handler to the form you’d like to validate – in this case, mine looks like this:

1
<form action="/ajaxValidate/index/success" method="POST" onSubmit="return submitForm(this);">

The form action is set to the page I’d like the script to go to if the validation is successful. The onSubmit calls a custom function that we still need to define. It passes ‘this’ as an argument – the ‘this’ refers to the form element itself.

Now we define the submitForm() function that the onSubmit of the form will call – it looks like the following:

1
2
3
4
5
6
function submitForm(form) {
	validator = new AjaxFormValidator(form,"/ajaxValidate/index/validate");
	validator.errorDisplay = 'inline';
	validator.inlineElem = 'errorDiv';
	return validator.validate();
}

This function first creates a new AjaxFormValidator object, passing it the form element (or the form id) and the url the validation request should be sent to. The next two lines setup the type of error display that should happen. The following error display types are supported:

  • alert: The default option. Displays all errors in a JavaScript alert box.
  • inline: Displays errors within an element that is defined on the page. You need to set the element name with validator.inlineElem. In this example, errors will be shown in a div with id=”errorDiv”.
  • none: errors won’t be shown to the user. The will be available as an array of errors in the errors property of the validator (i.e. validator.errors). If there are no errors the property will be set to false. Once you have the errors you can perform more advanced error handling/display to the user.

Lastly, validator.validate() will send the values in the form, in an HTTP POST, to the validation url you’ve provided (/ajaxValidate/index/validate in this case). If there are no errors the form will be submitted, if there are errors the will be shown (or not shown if you’ve chosen ‘none’ as the errorDisplay).

The PHP

Once the request is sent it will eventually arrive at the server for processing – in this case, through the magic of routing, it is going to end up in my IndexController in the validateAction method. This function is shown below:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
public function validateAction() {
	$errors = $this->getErrors($_POST);
	if(count($errors) == 0) $errors = false;
	echo Zend_Json::encode($errors);
}
</php>
This function calls another method within the IndexController class called getErrors, passing in the entire array of POST arguments (values in the form).  It receives back an array full of error strings.  If there are no errors, it changes the value of the $error variable to false.  Lastly, it uses Zend_Json to convert the PHP array/Boolean into the equivalent JavaScript array/Boolean.  This string is printed and sent back to the client.
 
The getErrors function itself is very straightforward - it just does a couple validations and returns back an array of the errors.
<pre lang="php" line="1">
protected function getErrors($values) {
	$errors = array();
	if(!Zend_Filter::isRegex($values['fname'],'/^[a-z]+[a-z 0-9-_]*$/i')) {
		$errors[] = 'First Name is required and may only contain letters, numbers, and spaces';
	}
	if(!Zend_Filter::isRegex($values['lname'],'/^[a-z]+[a-z 0-9-_]*$/i')) {
		$errors[] = 'Last Name is required and may only contain letters, numbers, and spaces';
	}
	if(!Zend_Filter::isRegex($values['email'],'/^[_a-zA-Z-]+[._a-zA-Z0-9-]+@[a-zA-Z0-9-]+\.[.a-zA-Z0-9]+$/')) {
		$errors[] = 'Email is required and must be a valid email address';
	}
	if(!Zend_Filter::isAlnum($values['password']) || (strlen($values['password']) < 6) || (strlen($values['password']) > 12)) {
		$errors[] = 'Password must consist of only letters and numbers and must be between 6 and 12 characters';
	}
	return $errors;
}

Check it out, in action. And that’s about it – pretty simple, huh?

You can download:

gCards Forum Up!

Posted on July 3rd, 2006 in PHP, Uncategorized, gCards by Greg

Many folks have complained since I took down the forum that was up for the support of gCards. Now, I’ve got a new forum up, this one powered by Vanilla. Hopefully it’ll do a bit better than the last one.

Check it out

Experimenting with Google Checkout and PHP

Posted on July 1st, 2006 in PHP, Technology, Web Development by Greg

Having put together a couple websites (Redstone Studios and Althea) that integrate with Paypal for providing checkout capabilities, I was very interested to look at Google Checkout when it was released this past week. My experience with the Paypal integration was not so good – while I eventually got it to work, it took a ton of experimentation, searching for documentation, and guessing why things weren’t working (i.e. no meaningful error messages). Luckily, Google Checkout doesn’t seem to suffer from these problems – I had it up and running in no time and it seems very solid for what it does. What does it do? Well, it’s basically a checkout system where you can pass in a cart, users can pay by credit card, and then the money gets deposited in your bank account. Google charges 2% of the transaction amount plus twenty cents. The two percent covers the percent Google has to pay the credit card companies, and the twenty cents is some extra cash for Google. If you use Google Adwords, you get a free credit on Google Checkout – for every 1 dollar spent on Adwords you get 10 dollars of sales with no costs.

Google provides sample PHP code for getting the integration going, but unfortunately the code is PHP4 only, and it is ugly ugly ugly code. I decided to put together a simple class that allows simple integration with Google Checkout. The class is PHP5 only because it uses PHP5’s DOM extension.

To use Google Checkout you need to create a Google Checkout account. From there, you can get your merchant id and merchant key, both of which are needed to communicate with Google Checkout. The Google Checkout API works by POSTING XML over HTTP. While Google’s API is very flexible, I’ve chosen to implement a subset that I think would be useful for many people. Also, I’ve only implemented this class to support the creation of the cart and submission to Google, I haven’t included any functionality for greater integration. This greater integration would involve creating web services that Google could call to update the website on changes to the order status, shipping, etc. The way I’ve set this up, all of that is skipped, and store owner would receive orders via email or Google’s Checkout interface.

Limitations:

  • No support for cart expiration
  • No support for merchant calculations for tax/shipping/gift certificates as these require HTTPS and I don’t have it and don’t care to use it
  • No support for requesting the buyers phone number because I didn’t notice that field until just now!
  • No support for shipping restrictions – i.e. shipping option 1 is only available in these zip codes/states/etc
  • No support for complicated tax rules. Tax can be setup on a state by state basis. One alternative tax rule ‘taxfree’ is setup to allow certain items to be tax free. No support for other alternative tax rules.
  • Currently doesn’t support customization of the form and checkout image

In order to work around some of these limitations, I’ve provided a method called setDefaultXML which allows the developer to specify a default XML file to be used. The class will then fill in the items, do the encryption, and generate the form and checkout image. This allows much greater flexibility and support for all of Google’s options, when needed.

Here’s a simple example of how I might use it:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
require('GoogleCheckout.php');
 
$merchant_id = 'XXXXXXXXXXXXXXX';
$merchant_key = 'XXXXXXXXXXXXXXXXXXXXXX';
 
$google = new Gregphoto_Service_Google_Checkout($merchant_id,$merchant_key);
$google->setMode('sandbox');
$google->addItem('Doolittle','Doolitle CD by The Pixies (1989)','11.98',1);
$google->addItem('PSCREEN18','18 inch Pizza Screen','7.99',3);
$google->addItem('MYWIDGET01','New tax free widget - Student Use Only','149.21',1,'','taxfree');
$google->addItem('NDISC01','New Customer Discount','-10',1);
$google->editCartUrl = 'http://www.gregphoto.net/index.php?action=editcart&source=google';
$google->continueShoppingUrl = 'http://www.gregphoto.net';
$google->setShipping('UPS Ground',19.99);
$google->setShipping('UPS Next Day',27.99);
$google->setShipping('Instore Pickup',4.99,'pickup');
$google->setStateTax('CA',.0875);
$google->setStateTax('IL',.0525);
 
echo $google->getHTMLForm();
$google->printXML();

Now, for what’s going on:

  • Line 1 includes the class
  • Lines 3 and 4 setup variables for the merchant id and merchant key
  • Line 6 instantiates the class, passing in the merchant id and key
  • Line 7 sets the class to use the Google Checkout Sandbox – this is a testing sandbox where you can setup fake accounts to use while creating your site. Paypal offerers a much richer sandbox functionality.
  • Lines 8-11 add new line items to the cart, setting there name, description, price, quantity, notes, and special tax rules
  • Lines 12 and 13 setup the URLs the user should be sent to if the choose to edit the cart or continue shopping
  • Lines 14-16 setup various shipping options including their prices
  • Lines 17 and 18 setup taxes for the users in specific states. Google Checkout supports much richer rules around taxation, but I kept it simple on a state-by-state level.
  • Line 20 outputs the HTML form and checkout image that will send the cart to Google Checkout and bring the user to the Google Checkout page
  • Line 21 shows the XML cart, for debugging purposes

View this example running on my site
View the API of Gregphoto_Service_Google_Checkout
Download the class and API docs
View Google’s Develper Guide for Google Checkout