Forum Moderators: coopster

Message Too Old, No Replies

counting user actions

         

sssweb

2:46 pm on Nov 13, 2011 (gmt 0)

10+ Year Member



Is there a way to do either of the following:

1) Create a function with an internal counter that tracks how many times the function has been called on the page, without re-loading the page or in any way sending the count data to the function as a variable.

2) Create link code that counts how many times the link has been clicked and either: a) sends that count data to the link destination, or b) uses the count data to modify the link destination (i.e. add a running $count var to the end of the link destination code); the link destination may be a php function or an in-page bookmark, but again, all must be done without re-loading the page.

I found Countable::count() in the manual, but am unclear whether it works here.

penders

5:11 pm on Nov 13, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



1) How many times the function has been called during the generation of the page? Do you mean like a static variable [uk.php.net] (inside of a function)?

"...without re-loading the page."

2) User clicks a link and runs a script on the server... you need to look at the XMLHttpRequest JavaScript object (AJAX). Your link would call a local script that opens an AJAX request to the server (calling a server-side script and passing some id to identify that link). Lookup/update values in DB etc. The response from your script would tell your script what to do next, change link destination etc.

This link never goes to an external site?

sssweb

6:29 pm on Nov 13, 2011 (gmt 0)

10+ Year Member



1) No, I don't need the count from the page generation; the function call is in a link, and only called when the user clicks the link -- I need to count how many times the user has clicked the link.

2) That sounds like a possibility, though it's way over my head. If you still think it may work, can you point me somewhere for more info?

Basically, I need to set up an in-page nav system, using #bookmark links, with all links dynamically generated. Normally this is easy enough to do, but I also want the navigation links (simple "back" & "next" links) to display in the same position on the page, regardless of what text displays above them.

The problem I'm having is that when I set a fixed link position with CSS, the links don't scroll with the text; they are "stacked" on top of each other, with the same one (the last in the series) showing regardless of what text is above it. So I can't navigate unless I come up with a dynamic way for one link to handle the whole page.

sssweb

7:55 pm on Nov 13, 2011 (gmt 0)

10+ Year Member



I looked into the static variable thing -- that might work after all; I'll play around with it.

sssweb

8:28 pm on Nov 13, 2011 (gmt 0)

10+ Year Member



No, I don't think it will, because in this case (counting user clicks), it requires reloading the page.

From what I can tell, this can only be done with AJAX, so I will shift focus there: [webmasterworld.com...]