Skip navigation
Currently Being Moderated

Intercept variable present in swf

Apr 4, 2012 5:30 AM

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

 
Replies
  • Currently Being Moderated
    Apr 4, 2012 7:14 AM   in reply to kevinlomax

    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:

     

    1=100

    2=39

    abc123=14

     

    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:

     

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

                   $itemValue++;

     

                   # 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));

         fclose($filehandle);

    }

    ?>

     

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 4, 2012 7:51 AM   in reply to kevinlomax

    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

    ExternalInterface.call("SendBannerId","abc123");

     

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

                        data:"clickTAG="+bannerID

                   });

    }

    </script>

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points