Solved

Javascript & php counter on click

Posted on 2013-12-05
3
445 Views
Last Modified: 2013-12-12
Hi There

Does anyone know how to create a counter that will increment, when you click.  And it will save the number of clicks the next time you revisit the site.  If possible I need a php and javascript solutions.

Many Thanks
0
Comment
Question by:smaids123
  • 2
3 Comments
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 39699895
Javascript would not be needed, but it could be used to make a smooth "Ajax" communication with the server.  To that end, this article shows how to send data to the server and get the response back into the DOM.
http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Jquery/A_10712-The-Hello-World-Exercise-with-jQuery-and-PHP.html

What would be needed are a way to identify the returning client and a data base table to keep track of the clicks.  The client will be identified by the HTTP cookie.  The cookie will be associated with a row in the data base table.  Each time the request is fired, the PHP script will take the cookie, look up the row, add one to the counter.  If a request arrives without a cookie, it's a new client.  The script will generate a new, unique cookie, insert the row into the data base with a count of "1" and welcome the client.

If you're new to application development, this article has some excellent "getting started" learning resources.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html

Best of luck with your project, ~Ray
0
 

Author Closing Comment

by:smaids123
ID: 39713717
This is great,

And I have learnt some new things about Ajax.

Thanks
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39713988
Thanks for the points and thanks for using EE, ~Ray
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now