3 Replies Latest reply on Nov 16, 2010 1:21 PM by Graham vdR

    Flash receiving cookie info from php

    Graham vdR Level 1

      Hi there

       

      I have a very simple php script that I'm using to check and set a cookie. I'm running this script from a Flash file, but it's not working properly. If I enter the direct URL to the php file in my browser, it works perfectly. However, if I access it through Flash it doesn't seem to recognise that the cookie has been set.

       

      Here is my php code:

       

      <?
      
      $expiry = date("U", mktime(0, 0, 0, date("m"), date("d") + 1, date("y")));
      $vote = 4;
      
      if(isset($_COOKIE["votedA"])){
          $voted = $_COOKIE["votedA"];
          echo "&vote=$voted";
      }else{
          setcookie("votedA", $vote, $expiry);
          echo "&vote=2";
      }
      
      ?>
      

       

      And here is the relevant bit of ActionScript:

       

      function loadCookie(lvIn, cookie, box, starsIndex){
          lvIn.onLoad = function(success){
              if(success){
                  cookie = lvIn.vote;
                  if(cookie != 0){
                      for(i = 0; i < cookie; i++){
                          box.mc["star" + String(i+1)].gotoAndStop(2);
                      }
                      for(i = 0; i < 5; i++){
                          box.mc["star" + String(i+1)].enabled = false;
                      }
                      box.mc.textBox.text = "Thanks for voting!";
                  }
                  trace(cookie);
              }else{
                  cookieFail();
              }
          }
      }
      
      loadCookie(lvCookieA, cookieA, boxA, 1);
      

       

      The trace action in the ActionScript keeps returning 2, but by accessing the same php file directly from the browser it echoes 2 the first time and then 4 afterwards, as it should.

       

      Any ideas why this is happening? I'd appreciate any thoughts.

        • 1. Re: Flash receiving cookie info from php
          kglad Adobe Community Professional & MVP

          you're not calling a php file with that actionscript.

          • 2. Re: Flash receiving cookie info from php
            Graham vdR Level 1

            Sorry, I left out some of the code from my post.

             

            Here it is with, I hope, the other relevant bits included:

             

            var pathCookieCheckA:String = "http://www.petaldesign.co.za/crush/issue4/recipe_rating/checkCookieA.php";
            var cookieA:Number;
            
            function loadCookie(lvIn, cookie, box, starsIndex){
                lvIn.onLoad = function(success){
                    if(success){
                        cookie = lvIn.vote;
                        if(cookie != 0){
                            for(i = 0; i < cookie; i++){
                                box.mc["star" + String(i+1)].gotoAndStop(2);
                            }
                            for(i = 0; i < 5; i++){
                                box.mc["star" + String(i+1)].enabled = false;
                            }
                            box.mc.textBox.text = "Thanks for voting!";
                        }
                        trace(cookie);
                    }else{
                        cookieFail();
                    }
                }
            }
            
            loadCookie(lvCookieA, cookieA, boxA, 1);
            
            lvOut.sendAndLoad(pathCookieCheckA, lvCookieA, "POST");
            

             

            I haven't included all the variable declarations above, but I don't think it's necessary to show you the relevant code. (I could be wrong though.)

             

            What I find most confusing is that the trace returns 2, so it is definitely receiving that value from the php script but for some reason is not recognising that the cookie has been set, even though this works when I access the php file directly (using the URL in the first line of code above).

            • 3. Re: Flash receiving cookie info from php
              Graham vdR Level 1

              Ah! I think I have it. I tested it now at home and it worked first time. I couldn't believe it.

               

              When the php script is called from Flash the cookie must be stored in a different location, so it wasn't working for me at work because I had done various tests along the way and already set the cookie. When I tested it in Firefox and cleared the cookie I assumed it was the same cookie I was clearing. I tested it on a different computer now in Flash and then couldn't find the cookie in Firefox, until, of course, I tested the direct URL in Firefox.

               

              So my question is then: Where would the cookie be stored and how could I clear it manually for testing purposes? Firefox is my default browser, but it's obviously not going into the Firefox cookies.