Jump to content

Write a button to a text file


2JH

Recommended Posts

Hi, what I am trying to do is keep a record of all the buttons that are pressed in my website (in a text file) so that I can see the parts of the site that are used. The buttons are links between pages, so I want to see what is clicked from where etc.

 

At the moment I have the following:

<?php

if(isset($_REQUEST['button1']) || isset($_REQUEST['button2'])){

$file=fopen("welcome.txt","a") or exit("Unable to open file!");

if(isset($_REQUEST['button1']))

{

fwrite($file , "button 1 pressed");

}

if(isset($_REQUEST['button2']))

{

fwrite($file , "button 2 pressed");

}

if(fclose($file)){

echo "Finished closing file";

}

}

?>

 

<html>

<body>

 

<form name='noname' action='page1.php' method='get'>

<input type="submit" name='button1' value='button'>

</form>

 

<form name='noname' action='page2.php' method='get'>

<input type="submit" name='button2' value='buttonb'>

</form>

 

</body>

</html>

 

The problem with this is that although the buttons link to the page (simple HTML) they do not write to the text file when the page changes. If I change the HTML to <input type="submit" name='#' value='button'> then I get the record in the text file, but then the button is not doing its job.

 

Anyone got any ideas, help would be appreciated I have been trying to get this to work for ages now.

Link to comment
Share on other sites

I understand the point about the logic, but the problem that I am having is if I add in a third page. By logging the click in the page being pointed towards I can log all the clicks occuring in page 1 but when the user moves to page 2 then the clicks here are not recorded. I have created a series of test files:

 

File 1 - Just HTML button to point to page 

<html>

<body>

 

<form name='noname' action='p2.php' method='get'>

<input type="submit" name='button1' value='button'>

</form>

 

</body>

</html>

 

Page 2 -  record this and a HTML button to go back to page1

 

if(isset($_REQUEST['button1'])){

  $file=fopen("welcome.txt","a") or exit("Unable to open file!");

    if(isset($_REQUEST['button1']))

  {

      fwrite($file , "button 1 pressed\n");

  }

  }

?>

 

<html>

<body>

 

<form name='noname' action='p1.php' method='get'>

<input type="submit" name='button3' value='button'>

</form>

 

</body>

</html>

 

I have now changed file 1 so that it should record this button press occuring in page 2:

<?php

if(isset($_REQUEST['button1']) || isset($_REQUEST['button2'])){

  $file=fopen("welcome.txt","a") or exit("Unable to open file!");

    if(isset($_REQUEST['button3']))

  {

      fwrite($file , "button 3 pressed\n");

  }

      if(fclose($file)){

      echo "Finished closing file";

  }

}

?>

 

 

<html>

<body>

 

<form name='noname' action='p2.php' method='get'>

<input type="submit" name='button1' value='button'>

</form>

 

</body>

</html>

 

However the problem that I am having is that only the buttons pressed in page 1 are being recorded and not those in page 2. Any ideas??

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.