2JH Posted July 17, 2007 Share Posted July 17, 2007 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. Quote Link to comment Share on other sites More sharing options...
trq Posted July 17, 2007 Share Posted July 17, 2007 Is all this in one file? Think about the logic.... the button1 for instance requests page1.php, you need to log the click from within that file. Quote Link to comment Share on other sites More sharing options...
2JH Posted July 18, 2007 Author Share Posted July 18, 2007 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?? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.