Category Archives: php

php stuff

General Internet Stuff php

IIS PHP cURL Authorize.net SSL

I’ve been working on a checkout system for a client site… Everything works well on our local and dev servers, but when we launched to the production box, which happens to be IIS, the checkout bombs.

After digging, cursing, googling, complaining to the ISP, etc… I finally found out that apparently, IIS windows servers do not verify the connection… In fact it times out if you try to.

So, im posting this to help save someone else hours of frustration…  In your cURL call to an https url, you just need to add the following

curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // <-- Add this for IIS
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);

 

codeigniter matchbox & modular extensions php

Codeigniter Simpletest Modular Extensions Suite

Update…

I am still having issues with MB  - and apparently others are too view thread.  So, I am once again switching back to HMVC / Modular Extensions.. With that switch I am also converting the Simpletest module as well as my Tag and Template libraries over as well..

I’ll release them soon (this month…. really)

—-

So, I am primarily writing this pre-post as incentive for myself to have a deadline and accountability.

After reading Jaime Rumbelow’s post on Codeigniter and Simpletest I realized I needed a way to do TDD in my Matchbox modules without having to set everything up each time.

I have an almost ready matchbox simpletest module that scans other modules for tests and auto runs them.   Each module you want to build with TDD only needs to contain its tests (which can  run on their own by loading the simpletest lib from the simpletest module) or can be auto loaded in batch from the main simpletest module.

If you are interested in helping me beta test, let me know – i plan to release a beta somewhere around Feb 1.

codeigniter php

CodeIgniter Textmate Bundle

I Know this is a few days old already, but its just too good of a tool to not post in as many places as possible.

There is now a CodeIgniter Textmate bundle avaialable! If you are like me, you have a bunch of snippets already available for common CodeIgniter code. Well, David Ferguson wrote a CodeIgniter Textmate bundle that has snippets and shortcuts for every helper and class available in 1.7.2

codeigniter matchbox & modular extensions php

Matchbox is Back! So Long Modular Extensions…

So, for once, my procrastination has paid off! A while back i was complaining, in the most polite way of course, about the lack of development of matchbox. A few days ago Zacharias released Matchbox RC1.  He completely re-wrote it from the ground up and has made it 100% compatible with the latest Codeigniter release.

I downloaded the release candidate from http://codeigniter.com/wiki/Matchbox/, dropped it into a new branch of some projects that use the old version, and was off and running.

As i play with it more i plan to release some of our code like the AMFPHP library as self contained modules that can be dropped into an application.

Thanks again to Zacharias for all your hard work.

Phil

codeigniter mysql php

Snow Leopard / MAMP Pro mySQL woes

After wiping my computer and installing 10.6 from scratch, my local php/mysql would not work at all.  The biggest problem was that I was receiving an error when trying to connect to mySQL “Lost connection to MySQL server at ‘reading initial communication packet’, system error: 61″.

It turns our that in MAMP Pro 1.8, they left out the local bind-address declaration, which for some reason freaks out the default PHP/Apache setup.

So, if you are running Snow Leopard and MAMP Pro and can’t connect to your mySQL, it’s an easy fix.  In MAMP Pro edit your my.cnf template (File > Edit Template) .  Add this line somewhere after the “[mysqld]” declaration (and reload) – Everything should be good.

bind-address = 127.0.0.1

codeigniter php

Codeigniter Image Cache & Auto Size on Demand”

What

This ‘library’ for lack of a better description allows  designers to use libraries of high-res images anywhere in the site, at any size, without having to pre-define or pre-scale your images.  It can also be used on the fly with user uploaded photos in a gallery setting.

Why

Other alternatives I have found in both codeigniter and other frameworks/cms’s like Drupal, EE, and WordPress require the administrators to pre-define set image sizes like thumbnail, medium, large.  While this makes sense for a new site, it can be an issue if you want to redesing and start using a different size for thumbnails, previews etc.

Basic Usage Overview

To use the ‘library’,  all you need to do is set your img tag source to point to the controller with a few pre-defined uri segments.

Image Tag: <img src=”/img/size/o/folders_your_image_is_in-your_image.jpg/w/240/h/160/m/auto” />

* If you arn’t using .htaccess to mask your index.php.. change the path to index.php/img/size…..

Sample site using library: http://www.synlawn.com/gallery

Features

  • Fully customizable with little work
  • Can support any directory depth in any location (does not need to be web accessible)
  • Automatically caches called images in their original directory at called size so it only processes once
  • Can be dropped into any CI installation – It was even originally written as a Matchbox module
  • Maintains your image heirarchy and file name in source (for SEO) and keeps images available for external reference.
  • Uses default codeigniter img_library, nothing else to install (unless you do not have imagemagick, netpbm, gd, or gd2)
  • Uses a default ‘error/not-found’ image so you can stick a site logo on a high res image to use anywhere in case of an error (no image-not-found issues)

read more »

codeigniter flash php

Codeigniter AMFPHP library – updated

Update 11/24/09: In order to load other libraries/models into your models with AMFPHP, change the BASEPATH declaration in index.php to


define('BASEPATH', realpath(dirname(__FILE__)).'/'.$system_folder.'/');

This is more of a repost of my wiki page on Codeigniter’s site, but i needed filler content for my first few postings on my site.

At first glance there is a lot to digest, but it is actually a pretty simple installation and is basically just replacing the gateway file with a Codeigniter controller

What it does

This AMF library will give you full access to your Codeigniter Models, as well as any libraries. In other words, it was written to work with Codeigniter, as Codeigniter was intended to be used – and you can drop this into your existing setup.

How??

Instead of trying to bootstrap Codeigniter, or use models outside of your app.  We create a Codeigniter controller, and a Codeigniter AMFPHP library that uses AMFPHP as packaged. – Then you create an AMFPHP Services in the services folder that just extends your Codeigniter models, and gives you full access

Full Working Example

We have packaged up the entire working sample that includes a fresh Codeigniter 1.7.1, AMF 1.9 and 2 flash samples modified from the Open Source Flash Development book chapter by (Wade Arnold) and a sample product mysql table.

All of the sample code assumes you ARE NOT using a .htaccess file, and also assumes you are using the default everything.  If you have moved your app and system path outside your webroot (as you should) it should still work fine too.

Dowload the files

And away we go: Instructions / Explanation of whats going on

  • Download Codeigniter and AMFPHP (or pull apart the link above)
  • Make sure Codeigniter works as expected before moving forward
  • Put the unzipped amfphp package into your libraries folder
  • Create your amf_gateway.php in ‘controllers’

This file replaces the need for gateway.php
setup netConnection to ‘/index.php/amf_gateway’

class Amf_gateway extends Controller
{
  public function __construct()
  {
    parent::Controller();
    //Start our library (keep reading the tutorial)
    $this->load->library('amfci');
    //Set new include path for services
    ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . AMFSERVICES);
  }

//startup the amf gateway service
 public function index()
 {
  $this->amfci->service();
 }
}
  • Create a standard Codeigniter model or use an existing one
  • Drop in the amfci_db.php file provided into ‘libraries/amfphp/services/amfci_db.php’
  • Create AMFPHP Service in ‘libraries/amfphp/services’ folder using the template provided

This file is a service for AMFPHP – called from flash
This extends your existing model to give flash access to all its methods

//Load CI DB Instance since we are not coming through index.php
require_once('amfci_db.php');

// Use this path if you are using a module (ie, MatchBox)
// require_once(AMFSERVICES.'/../../../modules/test_shop/models/product_model.php');

// Use this path if you are using standard install
require_once(AMFSERVICES.'/../../../models/your_model.php');
class your_model_service extends your_model
{
  //Since extending your_model, all existing methods are available
  //New Methods
  public function yourNewMethod()
  {
    $something = array(); //Create array to send to flash
    return $something;
  }
}

Add the amfci.php library to your library folder The amfci library is used by amf_gateway controller that replaces the default gateway.php file, by creating an instance of the gateway as $this->gateway, and settign the needed options

This file is the new amfphp library for CI
It it loaded from the amf_gateway controller, and binds all of it together

class Amfci
{
  public $gateway;
  public $CI;
  public function __construct()
  {
    $this->CI = get_instance();
    require realpath(dirname(__FILE__))."/amfphp/globals.php";
    require realpath(dirname(__FILE__))."/amfphp/core/amf/app/Gateway.php";
    define('AMFSERVICES', realpath(dirname(__FILE__))."/amfphp/services");

    $this->gateway = new Gateway();
    $this->gateway->setCharsetHandler("utf8_decode", "ISO-8859-1", "ISO-8859-1");
    $this->gateway->setLooseMode();
    $this->gateway->setErrorHandling(E_ALL ^ E_NOTICE);
    $this->gateway->setClassMappingsPath(AMFSERVICES.'/vo');
    $this->gateway->setClassPath(AMFSERVICES);

    if(PRODUCTION_SERVER)
    {
      //Disable profiling, remote tracing, and service browser
      $this->gateway->disableDebug();
    }
  }

  public function service()
  {
    $this->gateway->service();
  }
}

Connect and call from flash

package com.page12.hello_world
{
  import flash.display.MovieClip;
  import fl.events.*;
  import flash.events.*;
  import flash.net.NetConnection;
  import flash.net.Responder;
  import flash.net.ObjectEncoding;

  public class Main extends MovieClip {
    private var gateway:String = "/index.php/amf_gateway";
    private var connection:NetConnection;
    private var responder:Responder;

    public function Main()
    {
      send_btn.addEventListener(MouseEvent.CLICK, sendData);
      responder = new Responder(onResult, onFault);
      connection = new NetConnection;
      //connection.objectEncoding = ObjectEncoding.AMF3;
      connection.connect(gateway);
    }

    public function sendData(e:MouseEvent):void
    {
      var params = server_txt.text;
      response_txt.text = 'Send '+server_txt.text+' to server';
      connection.call("hello_world_service.say", responder, params);
    }

    private function onResult(result:Object):void
    {
      response_txt.text = String(result);
    }

    private function onFault(fault:Object):void
    {
      response_txt.text = String(fault.description);
    }
  }
}