Jump to content


Photo

PHP & Swish?


  • Please log in to reply
3 replies to this topic

#1 Daisy

Daisy
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 19 May 2006 - 01:17 AM

Hi everyone

I am new to PHP so bare with me :(

I am using swish to write flash sites and what I need is a way to log clicks for certain "links".

Currently I am using a PHP script that allows me to do this but I have to have a seperate PHP and a seperate .txt file just to log a click number for each link/button.

What I would like to know is, if there is a way just to write to one log file but to have each link with a diffrent iD tag so in the log file it shows, for example: ID=link1 clicked 10 times ID=link2 clicked 5 times.....etc etc

Hope someon can clear me on this

Thanks

Daisy



#2 litebearer

litebearer
  • Members
  • PipPipPip
  • Advanced Member
  • 2,357 posts
  • Locationwhite lake michigan

Posted 19 May 2006 - 03:13 AM

Not sure but is this kind of what you had in mind?

the text file (button,score|button,score| etc etc)
(buttonclicks.txt)

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
01,3|02,25|03,17|04,18
[/quote]

the php file
<?PHP

function add_clicks($file,$what_button) {
    $contents = file_get_contents($file);
    $new_array=explode("|",$contents);
    $i=0;
    for($i=0;$i<count($new_array);$i++) {
        $done = FALSE;
        $temp_array = explode(",",$new_array[$i]);
        if($temp_array[0] ==$what_button) {
            $score = $temp_array[1];
            $temp_array[1] = $score + 1;
            $new_array[$i] = implode(",",$temp_array);
            $i = count($new_array);
            $done = TRUE;
        }
    }
    $contents = implode("|",$new_array);
    $fp = f open($file, "w");
    $write = f puts($fp, $contents);
    f close($fp);
    return $done;
}

#############################
#    this is the name of the text file
#    that keeps count of the clicks
#############################

$file = "buttonclicks.txt";

###############################
#    replace the value of this variable
#    with how you set the value of
#    the button clicked
###############################

$what_button = 3;

##########################################
#    run the function
#    if its not sucessful (FALSE) so something
#    if its successful (TRUE) do something else
##########################################

$done = add_clicks($file,$what_button);
if(!$done) {
    echo "Too bad";
}else{
    echo "Well done!";
}


?>
Note: the forum is still having difficulties with file operation
scripts, so remove the spaces after each 'f' in the file operations

Hope this helps.

Lite...

all the brothers were valiant!

[br][br]The truely intelligent people are not those who create the dots; rather they are they ones with the ability to connect the dots into a coherent picture

#3 Daisy

Daisy
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 19 May 2006 - 08:33 AM

Hi Lite

many thanks for the response.

Ok. I am not too clued when it comes to PHP but most of this makes sense. But the more I look at it the les it does! hahaha

Sorry if I sound dumb but what value would I have to add to the button in order for it to send the click info to the file?

With the old script i have this on the button RELEASE:

this.loadVariables("entrar_hit_counter.php?rn=");

Which obviously sends it to the PHP file which then writes it to the .txt file

Thank you again

Daisy



#4 litebearer

litebearer
  • Members
  • PipPipPip
  • Advanced Member
  • 2,357 posts
  • Locationwhite lake michigan

Posted 19 May 2006 - 11:39 AM

it all depends upon how YOU want your coding to be.

ie the simplest method (IMHO) would be to assign each button a unique numeric value. then pass this value to your php script via the post method.

Lite...

all the brothers were valiant!

[br][br]The truely intelligent people are not those who create the dots; rather they are they ones with the ability to connect the dots into a coherent picture




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users