Archive

Archive for December, 2008

Zend Amf now with php session support

December 30th, 2008

PHP session support is now enabled through the Zend Amf. To get started you need to update your Zend_Amf_Server class from the repository. You will also need to make sure you have Zend_Session for those of you that are using the framework on as use-at-will bases.

Once you have updated your server you will need to also update your bootstrap/endpoint file to start using sessions and tell Zend Amf to use sessions.

$server = new Zend_Amf_Server();
Zend_Session::start();
$server->setSession();

You now have session support for all of your services.

A session example
We are going to create the following example in order to showcase how sessions can be used in an application.

Flex zend amf php session example

Flex zend amf php session example

The flex application connects to this SessionTest a service that opens a session count variable that is incremented with the getCount method. There are also three utility methods to show how sessions are being handled. The method getSessionID returns the current php session id. The method updateSessionID tells php to regenerate the sessions id. Finally unregister destroys the count session variable to start the incrimination over on the next service call.

/**
 * Example class for sending a session back to ActionScript.
 */
class SessionTest
{
	/** Check if the session is available or create it. */
	public function __construct() {

		if (!isset($_SESSION['count'])) {
			$_SESSION['count'] = 0;
		}
	}

	/** increment the current count session variable and return it's value */
    public function getCount()
    {
    	$_SESSION['count']++;
    	return $_SESSION['count'];
    }

    /** return the php session id value */
    public function getSessionID()
    {
    	return session_id();
    }

    /** Tell's php to generate a new session id */
    public function updateSessionID()
    {
    	session_regenerate_id();
    }

    /** clear the refrence to the count session variable */
    public function unregister() {
    	unset($_SESSION['count']);
    	return true;
     }
}

The flex code just consists of calls to the remote methods. There is nothing that you need to do special in your ActionScript in order to handle sessions. Note that there are just methods and handlers for all of the service calls.



    
        
        	
        	
        	
        	
        
    
    


	

Sessions are used for state but Flex is state-full?
Using sessions is important for storing state on the server. This can be hard to wrap your head around when to store state in the client and sync that state with the server. My recommendation is that you should use sessions when you don’t trust the client or that the data is so important that you shouldn’t ever trust the client. Using sessions with Zend_ACL and Zend_Auth are great examples of when you want to keep state in client and validate that state in the server. If something changes that was not intentional invalidate the state and log the customer out.

Session Identifiers

This is import to do as frequently as you can in you application. A new session ID can decrease the ability for a cross site scripting attack to take over your session and become a logged in user. In this example I have used a php call but make sure that you check out the documentation on Zend Session and specifically Zend_Session::regenerateId()

A primary difference between an RIA written in Flex, ajax, etc is that it does not reload the browser. This means that the user can aggressively click on a button and the RIA does not have the new session id returned. You can start “loosing” data as the new call is being sent with an old session id. If you application has aggressive click make sure you test regeneration speeds with slow connections. A proxy tools such as charles can really help debug slow connections.

At a minimal regenerate an id on massive state changes of the application! Login, logout, privilege escalation, etc.

Click around on the demo below to see what I mean!

Session Example

Finally
Give me your feedback. Sessions will be in the next minor so there is still time to change things, document better, and make more examples. Have fun!

Flash Platform, Zend_Amf

Zend Amf+Auth+Acl == secured AMF communication

December 29th, 2008

Keigth Craigo created a great blog post on integrating Zend Auth and Zend ACL for doing authentication and access control on your Zend Amf service calls. Make sure you check it out. I used a similar setup to connect to OpenID and it took less than a day because of all that is in Zend Auth.

There is something that Keith is missing that I should have updated into SVN today so he can take advantage of it for another blog post. Keith thanks so much for putting this tutorial together. I greatly appreciate it!

Build a better Login with Adobe Flex, Zend_Amf, Zend_Auth, and Zend_Acl 

Zend_Amf

Adobe Devnet artical on Integrated PHP and Flex development with Zend Studio and Flex Builder

December 24th, 2008

Check out Richard Bates article on Integrated PHP and Flex development with Zend Studio and Flex Builder it is a good read! If you don’t have these two ide’s put together you are wasting a lot of time in your workflow. Thanks RIchard for putting this article together! Richard is one of the first bloggers who ever started releasing tutorials for Zend Amf. This was fantastic for me as I was heads down trying to add features and fix bugs and he was creating getting started documentation. THANKS! If you have not seen his CRUDdy Buddy application you really need to check it out. It is a slick code generator written in Adobe Air and of course can stub out classes for Zend Amf. Keep watching Richard’s blog flexandair.com as he is always releasing good stuff for those that are reading my blog!

Zend_Amf

Intro examples for Zend Amf

December 18th, 2008

In a constant balance between new features and documentation I am releasing the first ‘examples’ today. This is a long way from being full blown best practices or tuturials but I hope it is a starting point. In this first release I have added a Flash and Flex Hello World example and a class mapping example for Flex that shows how to get ContactVO’s from the server and bind them in Flex. Please let me know what you want next. 

Example files

Zend_Amf

Zend AMF updates and questions for AMFPHP users

December 16th, 2008

I have been cleaning up some code and test cases in Zend Amf before some more real development starts. If you had issues with class and method collision, ByteArray’s, array’s loosing there keys, documents, or not getting the errors that you wanted please check out the latest build. Also if you have any feature request or bugs please make sure you let me know! 

Zend Framework Issue Tracker for AMF

Next up is optimizing ArrayCollection and proxy object support. 

If you used returning native resources in AMFPHP can you please let me know which ones. 

One of the most impressive features of Flash remoting is the ease at which you can send back resultsets. AMFPHP is preloaded with a set of adapters for a variety of databases and database drivers, in particular:

  • MySQL
  • PostgreSQL
  • SQLite
  • MySQLi
  • MsSQL
  • ADODB
  • ODBC
  • Oracle (oci8 for PHP5)
  • PDO
  • PEAR::DB

AMFPHP, Zend_Amf

Zend and the Adobe Flash Platform eSeminar

December 2nd, 2008

 

Thursday, December 18, 2008 11:00 A.M. PST – Register Now
Rich Internet applications (RIAs) are everywhere. With Web businesses like Google and Yahoo! and brick and mortar companies like Harley Davidson and Sherwin Williams embracing RIAs for their online presence, the media buzz is giving way to the reality of a better Internet.

Adobe has recently contributed AMF support to the Zend Framework, allowing PHP developers to easily build Rich Internet Applications using Flex and Adobe AIR that interact with a PHP backend.

Lee Brimelow, a technical evangelist with Adobe, will give an introduction to Adobe Flex and Adobe AIR, and will walk through how to create a Flex application powered by PHP and the Zend Framework. Working with Zend Studio for Eclipse, and Flex Builder (an Eclipse plugin), Lee will demonstrate how to build, debug and deploy applications built with Adobe Flex, and how to have these same applications run on the desktop using the Adobe AIR runtime.

With this knowledge, developers will be able to easily build rich Internet applications that combine data from PHP and rich media like audio and video into a compelling application.

 

Flash Platform, Speaking, Zend_Amf