3 Replies Latest reply on Mar 2, 2010 9:45 AM by Matt Le Fevre

    Regarding - Login and Refresh

    venkatsyss

      hi,

       

      My Question is ,using username and password i have logged in.If the username and password is correct i have showed the pannel successfully login.If i was refresh the page it again asking the username and password.

       

      I could n't know how to solve the problem.

       

      Please provide me help to solve the problem.

       

      Thanks and Regards,

      venkat.R

        • 1. Re: Regarding - Login and Refresh
          Matt Le Fevre Level 4

          you want something like sessions or cookies

          • 2. Re: Regarding - Login and Refresh
            venkatsyss Level 1

            hi,

             

            Thanks for your kind reply.

             

            My question is, after i  have logged in using correct username and password.I moved to another panel which i was defined in the resultHandler event .After i was moved the pannel however  if i have refresh the page they again taken into the login form.

             

            I could n't know why they had taken into the login page that was i have already login.

             

            Whether i have to set in the userid in flex or php.

             

            Please provide me the solution to solve the problem.

             

             

            Thanks and Regards,

            venkat.R

            • 3. Re: Regarding - Login and Refresh
              Matt Le Fevre Level 4
              I could n't know why they had taken into the login page that was i have already login.

               

               

              because you're not storing the login information anywhere, or even attempting to retrieve it.

               

               

              Heres a small very crude example flex app that uses PHP cookies to remember a login name, it should get you started.

               

               

              Flex code:

              <?xml version="1.0" encoding="utf-8"?>
              <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" applicationComplete="checkCookie()">
              
              
                  <mx:Script>
                      <![CDATA[
                          import mx.rpc.events.ResultEvent;
                          
                          [Bindable]
                          public var loggedUser:String;
                          
                          public var remeberMe:Boolean;
                          
                          public function checkCookie():void
                          {
                              getCookie.send();
                          }
                          
                          public function handleLogin():void
                          {
                              loggedUser = txt1.text;
                              currentState = 'loggedIn';
                              
                              if (checkbox1.selected)
                              {
                                  remeberMe = true;
                              }
                              
                              
                              if (remeberMe == true)
                              {
                                  setCookie.send();
                              }
                              
                          }
                          
                          public function handleCookie(evt:ResultEvent):void
                          {
                              trace(evt.result.cookie);
                              if (evt.result.cookie == "none")
                              {
                                  //do nothing
                              }
                              else
                              {
                                  txt1.text = evt.result.cookie;
                                  remeberMe = true;
                                  handleLogin();
                              }
                          }
                          
                      ]]>
                  </mx:Script>
                  
                  <mx:HTTPService id="getCookie" result="handleCookie(event)" showBusyCursor="true" method="POST"  url="http://localhost/flex/cookieGet.php" useProxy="false"/>
                          
                     <mx:HTTPService id="setCookie" showBusyCursor="true" method="POST"  url="http://localhost/flex/cookieSet.php" useProxy="false">
                          <mx:request xmlns="">
                              <cookie>
                                  {loggedUser}
                              </cookie>                
                          </mx:request>
                     </mx:HTTPService>
                     
                     <mx:HTTPService id="deleteCookie" showBusyCursor="true" method="POST"  url="http://localhost/flex/cookieDelete.php" useProxy="false"/>
                      
                  <mx:states>
                      <mx:State name="loggedIn">
                          <mx:RemoveChild target="{button1}"/>
                          <mx:RemoveChild target="{checkbox1}"/>
                          <mx:RemoveChild target="{txt1}"/>
                          <mx:RemoveChild target="{panel1}"/>
                          <mx:AddChild position="lastChild"> 
                              <mx:Label fontSize="20" x="10" y="10" text="{loggedUser} has Successfully logged in!" width="1050"/>
                          </mx:AddChild>
                          <mx:AddChild position="lastChild">
                              <mx:Button x="144" y="49" label="Delete any cookies" click="deleteCookie.send()"/>
                          </mx:AddChild>
                      </mx:State>
                  </mx:states>
              
                  <mx:Panel width="250" height="179" layout="absolute" id="panel1">
                      <mx:Button x="87" y="71" label="Login" id="button1" enabled="{txt1.text != ''}" click="handleLogin()"/>
                      <mx:TextInput id="txt1" x="10" y="10" height="23" width="210"/>
                      <mx:CheckBox x="60.5" y="41" label="Remember me" id="checkbox1"/>
                  </mx:Panel>
                  
              </mx:Application>
              

               

               

               

              PHP code:

               

              cookieSet.php

               

              <?php
              
                  $value = $_POST["cookie"];
              
                  setcookie("TestCookie", $value, time()+3600);  // expires in 1 hour
                  
              ?>
              

               

              cookieGet.php

               

              <?php
              
                  if ($_COOKIE["TestCookie"])
                  {
                      echo "<cookie>".$_COOKIE["TestCookie"]."</cookie>";
                  }
                  else
                  {
                      print "<cookie>none</cookie>";
                  }
              
              ?>
              

               

              cookieDelete.php

               

              <?php
              
                  setcookie("TestCookie", "foobar", time()-3600);
                  
              ?>