Saturday, August 9, 2008

PHP Session in flex.....

A sample application to demonstrate the session id using flex and PHP

Whenever you press the hts.send button in the upper left corner...The count value is returned for that session.

The right corner login button is used for the login management...

The trick in php is the session ID managed by the browser cookies to save it...
ini_set ( 'session.use_cookies', 1); 

ini_set (' session.use_only_cookies', 1);

PHP Code:


ini_set('session.use_cookies'     , 1);

ini_set('session.use_only_cookies', 1);


$_SESSION['cnt'] ++;

if( $_POST['name'] == "testuser" && $_POST['passwd'] == "testpwd" ){

    $_SESSION['login'] = 1;


    $_SESSION['login'] = null;

    unset( $_SESSION['login'] );


var_dump( $_POST);

var_dump( $_GET);

var_dump( $_COOKIE );

var_dump( $_SESSION );


Flex Code:

<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="" layout="absolute" creationComplete="init()">



            private function init():void{


            private function submitLogin():void{

                hts.method = "POST";







    <mx:HTTPService id="hts" url="http://yoursite/sessionTest.php" resultFormat="object"/>

    <mx:TextArea x="10" y="39" width="310" height="365" text="{hts.lastResult}"/>

    <mx:Button x="245" y="9" label="hts.send" click="{hts.send();}"/>

    <mx:Panel x="342" y="20" width="336" height="238" layout="absolute" title="Login Form">

        <mx:Form x="30" y="30">

            <mx:FormItem label="Usename" required="true">

                <mx:TextInput id="nameTxt" text="testuser"/>


            <mx:FormItem label="Password" required="true">

                <mx:TextInput displayAsPassword="true" id="passwdTxt" text="testpwd"/>



        <mx:Button label="Login" click="submitLogin()" x="212" y="120"/>




View the application here....


William said...

View Source isn't working for this. Can you post the source?


C├ęsar said...

yes! i want this, pls.

lonesailor said...

@William, @Cesar, My server crashed where I launched all my applications. Could you guys send me your mail. I will send the source code.

subash said...

Hey i want exactly this. Could you send please. my mail id is

subash said...

I need exactly this. Could you send source please? my mailid is

dominik.knoll said...

Yes, I'm too. Can you send me the source please?

Matthew said... would also like please

david.kagiri said...

send one too to davykiash{@}

jrodriguez said...

hi, please send me the code :) thanks!

Sohail said...

please send me code at .. Thanks

Faruq said...

Hi Can you send Source for me also. my emailid is

And can you explain how can i check session is available or not for each request? if you provide any example for this will be good for me.
Thanks in advance

Iqbal said...

Hallo, can you send me the source too? I need that incredible source.

Iqbal said...

I need that incredible source! send to please. Thx

rims said...

I need that incredible source! send to please. Thx

rims said...

I need that incredible source! send to please. Thx

GIlbert said...

send me to my mailid too