A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Passing variables using PHP - help needed

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    5

    Passing variables using PHP - help needed

    Hi all,

    I have a problem and hoping one of you Flash boffins on here might be able to offer me some help. I'm not very good with flash...

    Ok here goes. I have a flash file which registers button clicks and writes the responses out to a .csv file via PHP. This is all working perfectly in Firefox, Safari and IE but it's not working in Chrome or Boat (and a few other Android browsers).

    I've checked all the permission on the server and everything is 777 so I don't think that's the problem.


    Actionscript
    //Code for buttons
    button01.onRelease = function(){
    getURL("http://www.google.co.uk","_self")
    storeInformation("Google");
    }

    // Post to PHP
    function storeInformation(btnName:String){
    date = new Date();
    btn_name = btnName;
    press_date = date.toString();
    loadVariables("tracking.php", this, "POST");
    }


    PHP
    <?php
    $file = "output.csv";
    $name = $_POST['btn_name'];
    $date = $_POST['press_date'];
    $open = fopen($file, "a+");
    fwrite($open, "\r\n" . $name . ", " . $date);
    fclose($open);
    ?>


    All help most appreciated
    Last edited by Dazzer1977; 04-10-2012 at 06:01 PM.

  2. #2
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    This is beyond my capabilities, as I have no idea why it's not working on some browsers, and by mentioning Android browsers, I assume this is not working in mobile phones only, right? Because I myself use Chrome on Windows, and this method is working perfectly!

    There is another better method to achieve the same, so try that one instead. Change storeInformation function to this:

    Actionscript Code:
    function storeInformation(btnName:String){
        date = new Date();
        loadVars = new LoadVars();
        loadVars.onLoad = function(success){
            if(success){
                // info from PHP successfully received
            } else {
                // an error occurred
            }
        }
       
        sendVars = new LoadVars();
        sendVars.btn_name = btnName;
        sendVars.press_date = date.toString();
        sendVars.sendAndLoad("tracking.php", loadVars, "POST");
    }

    And then change your PHP file to this:

    PHP Code:
    <?php
        $file 
    "output.csv";
        
    $name $_POST['btn_name'];
        
    $date $_POST['press_date'];
        
    $open fopen($file"a+");
        
    fwrite($open"\r\n" $name ", " $date);
        
    fclose($open);
        echo 
    "success=true";
    ?>
    Hope this works, otherwise, I'm afraid I can't help you any further
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center