3 Replies Latest reply on Apr 4, 2012 7:51 AM by sinious

    Intercept variable present in swf


      Hello to all, within a few banners that I'm realizing I insert a variable, clickTAG, as a step in the url of the landing page after the click.

      Because the variable changes, I would like to capture this variable externally to externally store how many times you see a banner and how many times you see another.

      I like using some language asp, php or javascript to extrapolate outside this value?

      Hello and thanks in advance

        • 1. Re: Intercept variable present in swf
          sinious Most Valuable Participant

          This is more of a server side programming question than flash. Anyhow you could simply add a unique id to each different banner. All that would be left is, when clicked, PHP or ASP reads the ID and increments the number of times that banner has been read.


          In PHP you could do this a number of ways. I'll illustrate the absolute easiest (non-database). Just reading and writing to a text file.


          This assumes:

          - Your banner will include clickTAG as a URL argument, e.g. http://www.somewhere.com?clickTAG=1


          After that you can simply write each ID and its value to a delimited text file. I'll use newlines and equal signs to separate values.


          After the PHP page is hit, it will look for clickTAG, get the ID, read a text file, incremenet that ID and save the text file.


          The text file (say bannerclicks.txt) looks like this:






          Representing banner id 1 was clicked 100 times. Banner id 2 was clicked 29 times. Banner id abc123 was clicked 14 times.


          e.g. page.php:



          # check for clickTAG, and that its not empty

          if ( (isset($_GET['clickTAG'])) && (!empty($_GET['clickTAG'])) )


               # a simple cleanse clickTAG from injections

               $_GET['clickTAG'] = htmlspecialchars($_GET['clickTAG']);


               # read all previous ids from text file into an array

               $ids = file("bannerclicks.txt");


               # save a flag for if this value was updated, otherwise we'll need to add it

               $foundValue = FALSE;


               # iterate over ids, find this id

               foreach ($ids as &$id)


                    # inexpensive stristr match against this id

                    if (stristr($id, $_GET['clickTAG'] . '='))


                         # found the value

                         $foundValue = TRUE;


                         # extract the id and value separately (yes this could be done with a preg_replace in one step, I'm keeping it easy)

                         list($itemID, $itemValue) = explode("=", $id);


                         # increment value



                         # re-assign the reference

                         $id = $itemID . '=' . $itemValue;




               # didn't find value? add it

               if ($foundValue === FALSE)


                    array_push($ids, $_GET['clickTAG'] . '=1');



               # save file

               $filehandle = fopen("bannerclicks.txt","w");

               fwrite($filehandle, implode("\r\n",$ids));





          Security always being my utmost concern, all I did here to prevent injections was convert any value sent via clickTAG to HTML entities, e.g. < to &lt;. That doesn't guarantee no injections but it makes it harder.


          A better security model is to decide what a valid id can be and modify the security to suit. Like an ID can only be 4 digits followed by 4 letters and use a regular expression to match against it, otherwise discard it.

          • 2. Re: Intercept variable present in swf
            kevinlomax Level 1

            hello, thanks for reply.

            I had a look at your answer, but maybe I should not have been clear in my question I,  sorry for my English.

            I would not know the number of clicks, but well the number of impressions made by a banner

            from what I understand from your script, here I am going to count and save the number of clicks for each banner

            Thank you for your help

            • 3. Re: Intercept variable present in swf
              sinious Most Valuable Participant

              The easiest way to do that, which can be mixed exactly with the code I just gave you, is to send an ajax request to that PHP page containing the ID of the banner. It will save it just the same. To do that, it's easiest and often best practice to use a framework for javascript so it handles differences in browsers properly.


              Download or point to jQuery the JavaScript framework so you can easily do this. Include jQuery on your page. That will make the ajax a cinch.


              In flash you will need to include the ExternalInterface class and use it to call a javascript function I'll write below, e.g.:


              import flash.external.ExternalInterface;


              // send request that banner abc123 has been loaded



              Now in JavaScript you need a function mentioned above in the call:


              <script type="text/javascript">

              // function called from actionscript banner

              function SendBannerId(bannerID)


                   // create ajax request sending the bannerID received to the PHP file

                   $.ajax({ url:"some.php",