Jump to content

Which Programming language?


Recommended Posts

got a bit of a project to do. Involves turning a document into a set of html pages. The document is basically a code/guide which a user uses to accomplish a task of one type or another.

There are instructions in the document along the lines of :

if the project meets criteria a and b goto to page 10 table 2

Obviously these instructions will be the hyperlinks.

What I need is to record the links that a user follows when working through the code/guide and output the steps as a text file.

Any advice on which would be the best language to do this in in terms of ease of use, how easy and quick to learn etc.

I am very comfortable coding xhtml and css but would need to learn something new(which is good) if something like php is suggested. Alternatively is there a short piece of code for doing something like this that I could jig around?

Thanks in advance for any help guys.

Link to comment
Share on other sites

Ok after a bit of reading it looks like the quickest language to learn that might enable me to accomplish the task is probably javascript .

After a quick perusal of some online tutorials it seems that if I use the onClick command to write the link that has been clicked to a text file that might do it. I just need to find how I can read the link and write it to a file using the onclick command. <_<

Maybe by using the history or location file object? thing is finding out how to start a new one and end it every time a user uses the web document and outputting it in a nice form

Link to comment
Share on other sites

Nix on using either the history or location file objects I think.

Looks like the way to go is to include an event handler - in the case onClick , in every link ,that passes on a string(the link text) to a function in the Head of the HTML


<a href"link1" onClick="myfunction("link1")"> link1 text </a>

although I'm thinking maybe I shouldn't use double quotes around the string link1 as this could close the myfunction call?

Next thing is to find how to write a function I can use in the HEAD to write this string out to a text file? Can it even be done?

Any help any1?

Link to comment
Share on other sites

I would use a Session.

Include a php file on every page. When any page loads, append the page name to the Session item, comma separated.

When the person loads the "start" page, clear the Session item.

When the person reaches the "end" page, interrogate the session to recieve something looking like "Page1.html,Page5.html,Page9.html". Split the string by commas into an array, then loop through the array building the route that was taken. So the final page would just be a loop to include the appropriate content and might look like:

INCLUDE Page2.html
INCLUDE Page5.html
INCLUDE Page9.html


Sessions in PHP

PHP include

Link to comment
Share on other sites

Yeah javascript is not going to work, its client sided anyway, the user would be able to modify the log file...

anyway you didn't really make it that clear what your trying to do? what is your guide?

I'm guessing your providing links that the user can click on and use them to help him finish whatever "test" or whatever they are doing.

and so you want to record/log all of the 'help' pages they use to complete the test...

its very simple in php...

heres an example script which saves the pages clicked on into a log file in a folder... is more than 1 person going to be doing this test at a time? that makes a difference.. is a text log file going to be good enough? or should you go with a mysql database? well the example is for text file logging for now...


$TotalPages = 30;
$self = $_SERVER['PHP_SELF']; //the url to this script
$ip = $_SERVER['REMOTE_ADDR']; // ip address of user

$currentdir = realpath("."); // get current directory
$currentdir = str_replace("\\", "/", $currentdir);

$saveto = "$currentdir/$ip"; // append IP address to path
mkdir($saveto);              // make the directory
$saveto = "$saveto/log.txt"; // append 'log.txt' so it saves the log into the correct directory

// keep in mind cookies have to be dealt with before the &lt;html&gt; tag
if($_GET['testended'] == 1 &amp;&amp; isset($_COOKIE['testsession'])) // user clicked im finish link
  $cookiedata = $_COOKIE['testsession']; // grab data from cookie
  list($ipaddy, $starttime) = split('-', $cookiedata); // separate it into two variables
    setcookie("testsession", "", time()-3600); // delete the cookie by making it expire
    $f = fopen($saveto, 'a'); // open the log file with the correct path
  $time = date("h:i:s A");  // get current time
  $totaltime = time() - $starttime; // total time elapsed between start and end in seconds
  $totaltime = $totaltime / 60; // convert to minutes
  $fmtstring = "[$ipaddy] Session lasted $totaltime minutes, and ended at $time\r\n";
  fwrite($f, $fmtstring);
  echo "&lt;center&gt;&lt;h1&gt; Test Over!&lt;br&gt; it took you $totaltime minutes&lt;/h1&gt;";
else if(!isset($_COOKIE['testsession'])) // cookie doesn't exist so start the session
  $starttime = time();
  $cookiedata = "$ip-$starttime"; //cookie contains ip address of user and start time separated by a "-"
  setcookie("testsession", $cookiedata, time()+3600); // set cookie to expire in 1 hour(3600 seconds)
  $f = fopen($saveto, 'a'); // open the log file and append to the end of it
  $time = date("h:i:s A");
  $fmtstring = "\r\n[$ip] Session started at $time\r\n";
  fwrite($f, $fmtstring);

&lt;head&gt;&lt;title&gt;Example Link Logger&lt;/title&gt;&lt;/head&gt;

if(isset($_GET['Page'])) // if the user clicked on a page
  $page = $_GET['Page']; // get page number from url
  $f = fopen($saveto, 'a');
  $time = date("h:i:s A");
  $fmtstring = "[$ip] went to page $page at $time\r\n";
  fwrite($f, $fmtstring); // writes the $fmtstring to the log
  echo "&lt;meta http-equiv='refresh' content='0;url=$self'&gt;"; // reloads the page immediately
  for($i = 1; $i &lt;= $TotalPages; $i++) // creates page links to click on(just for example purposes)
    $pagex = "$i ";
    echo "&lt;a href='$self?Page=$i' target='NewWindow'&gt;$pagex&lt;/a&gt;";
  echo "&lt;p&gt;&lt;a href='$self?testended=1'&gt;Im Finished!&lt;/a&gt;"; // deletes the cookie and ends the session


heres how my log file looked after clicking some pages, then clicking im finished(i did it twice)

saved to the where the php file was \\log.txt

[] Session started at 10:36:46 AM
[] went to page 1 at 10:36:57 AM
[] went to page 2 at 10:37:02 AM
[] went to page 18 at 10:37:09 AM
[] went to page 29 at 10:37:12 AM
[] went to page 30 at 10:37:12 AM
[] Session lasted 0.73333333333333 minutes, and ended at 10:37:30 AM

[] Session started at 10:37:43 AM
[] went to page 6 at 10:37:45 AM
[] went to page 14 at 10:37:48 AM
[] went to page 25 at 10:37:50 AM
[] went to page 17 at 10:39:48 AM
[] Session lasted 2.0833333333333 minutes, and ended at 10:39:48 AM

this is just an example to build off of and is not complete...

I would make it create the folders and save the log file to them using a persons name instead of the ip address/ since you can tell who is who easier... create an edit box and grab the persons name before creating the cookie...

and to make it actually go to the pages, you could either, use some javascript to make the a window popup and goto the page(must disable popup blocker)

or use frames, create all the links that you want to guide people with in 1 frame, then the page to view in another frame, when a page is clicked record it, then make the view frame goto the page...

another thing you might want to consider is using a mysql database instead of text files, I think it would make it a little easier, but thats just me... ;)

and rab's session idea is a good idea too, I haven't thought of that

Link to comment
Share on other sites

Rab> thanks for your reply. I have followed your links and am checking out using sessions.

Steve> Sorry for not explaining more clearly . Have looked at your code and it has enlightened things for me a bit.

The web pages are not a test, its a sort of design code for an engineering process. A written document that takes a user through to an answer in a flowchart sort of way. eg: if conditions 1 and 2 are met go to page 10 section 2, if condtions 3 and 4 are met go page 10 section 3 and so on until the process is complete

So I really need to record the links that a user clicks rather than just the pages visited.

The results for one user need to be written to a text file. When another user uses it a different text file etc.

Link to comment
Share on other sites

You could totally make that a wicked AJAX App. Which really isn't that hard once you understand the basics.

you could either use files on the server or a database in the background for the data.. or hardcode it all in.

You could even have Steve8x's php (modified of course) fire everytime someone click a link as well as display the new information. It would be neat as well as efficient as the user wouldn't have to deal with page reloads (dunno about other people, but it seems to break my flow of concentration when a page reloads :P)

Link to comment
Share on other sites

Join the conversation

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

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...