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:


<?php

ini_set('session.use_cookies'     , 1);


ini_set('session.use_only_cookies', 1);


session_start();



$_SESSION['cnt'] ++;



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

    $_SESSION['login'] = 1;


}else{


    $_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="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">


    <mx:Script>


        <![CDATA[


            private function init():void{


            }


            private function submitLogin():void{


                hts.method = "POST";


                hts.send({


                    "name":nameTxt.text,


                    "passwd":passwdTxt.text


                });


            }   
        ]]>


    </mx:Script>


    <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>


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


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


            </mx:FormItem>


        </mx:Form>


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


    </mx:Panel>


</mx:Application>




 









View the application here....

16 comments:

Unknown said...

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

Thanks,
BD

Jagox said...

yes! i want this, pls.

Ram 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 Selvaraj said...

Hey i want exactly this. Could you send please. my mail id is subash.multimedia@gmail.com

Subash Selvaraj said...

I need exactly this. Could you send source please? my mailid is subash.multimedia@gmail.com

Unknown said...

Yes, I'm too. Can you send me the source please? dee-singen@arcor.de

Matthew Robinson said...

mattr1981@googlemail.com would also like please

Unknown said...

send one too to davykiash{@}gmail.com
please.Thanks

jrodriguez said...

hi, please send me the code :) thanks!

f.g.rodriguez.jr@gmail.com

Unknown said...

please send me code at pukarpukar@gmail.com .. Thanks

Unknown said...

Hi Can you send Source for me also. my emailid is faruq1256@gmail.com.

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. moo.iqbal@gmail.com

Iqbal said...

I need that incredible source! send to moo.iqbal@gmail.com please. Thx

rims said...

I need that incredible source! send to squalgal@gmail.com please. Thx

rims said...

I need that incredible source! send to squalgal@gmail.com please. Thx

GIlbert said...

send me to my mailid too ..reachgilly@gmail.com