tabs Posted July 7, 2008 Share Posted July 7, 2008 I'm looking at using a session and includes to monitor the links clicked on and the order by a user when an intranet document is used. I can write the data to a test file using fopen but I need to know how to gather the data ? Any ideas? Is there something similar to the onClick command in javascript that will pass a string (in this case the link name clicked) onto a function and this then writes it to the text file? thanks for any help Quote Link to comment https://forums.phpfreaks.com/topic/113588-recording-links-clicked/ Share on other sites More sharing options...
rhodesa Posted July 7, 2008 Share Posted July 7, 2008 well, no matter what you will need to use some sort of server side language here (i'm going to assume PHP) for internal pages, just record $_SERVER['REQUEST_URI'] every time the page loads for external pages, make the links go to an internal page that can then redirect like: link.php?url=http://www.hostname.com/external/page.html then in link.php record the value of $_GET['url'] is that what you are looking for? if so, this should be moved to the PHP forum Quote Link to comment https://forums.phpfreaks.com/topic/113588-recording-links-clicked/#findComment-583707 Share on other sites More sharing options...
tabs Posted July 7, 2008 Author Share Posted July 7, 2008 Cheers, yes probably needs moving to php forum. There will be no external links used though. Quote Link to comment https://forums.phpfreaks.com/topic/113588-recording-links-clicked/#findComment-583834 Share on other sites More sharing options...
lemmin Posted July 7, 2008 Share Posted July 7, 2008 You can do this all client side since it is local. Do something like this: <script> function writeLog(link) { //write link to a file } </script> <a href="page.htm" onClick="writeLog(this.href)">test</a> I think Scripting.FileSystemObject is what you need to write the file. Quote Link to comment https://forums.phpfreaks.com/topic/113588-recording-links-clicked/#findComment-583857 Share on other sites More sharing options...
rhodesa Posted July 7, 2008 Share Posted July 7, 2008 put this code in a file <?php session_start(); if(!is_array($_SESSION['pages'])) $_SESSION['pages'] = array(); array_unshift($_SESSION['pages'],$_SERVER['REQUEST_URI']); ?> and include it at the top of every page. it will build an array with all the pages the person has visited. The 0 index will always be the current page, 1 is the last page, 2 the second to last page, etc. So, to print the last page, after you do the include of the above code just do: <?php if($_SESSION['pages'][1]) print $_SESSION['pages'][1]; ?> Quote Link to comment https://forums.phpfreaks.com/topic/113588-recording-links-clicked/#findComment-583868 Share on other sites More sharing options...
tabs Posted July 7, 2008 Author Share Posted July 7, 2008 You can do this all client side since it is local. Do something like this: <script> function writeLog(link) { //write link to a file } </script> <a href="page.htm" onClick="writeLog(this.href)">test</a> I think Scripting.FileSystemObject is what you need to write the file. Isn't FileSystemObject an ASP component? (probably displaying my beginner status here.) Quote Link to comment https://forums.phpfreaks.com/topic/113588-recording-links-clicked/#findComment-583968 Share on other sites More sharing options...
lemmin Posted July 7, 2008 Share Posted July 7, 2008 It is a windows scripting object that you have to create: set fso = CreateObject("Scripting.FileSystemObject"); set s = fso.CreateTextFile("C:\test.txt", True); s.writeline("HI"); s.Close(); Quote Link to comment https://forums.phpfreaks.com/topic/113588-recording-links-clicked/#findComment-583971 Share on other sites More sharing options...
ToonMariner Posted July 9, 2008 Share Posted July 9, 2008 not sure the session is actually that useful here - to record ALL data you will need to log it on every page load. This would mean writing a snippet that is included in every page that opens a file (maybe a file per user so you don't get any problems with locks) and logs the data required on a new line. Client side is pointless as you won't have access to the data... If your requirement is a little less strict then perhaps you could collect data in a session array and dump it say every time the array hits 5 records - may help a little on performance but lets be honest its not going to make a massive difference. Quote Link to comment https://forums.phpfreaks.com/topic/113588-recording-links-clicked/#findComment-584930 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.