Solved

Javascript & php counter on click

Posted on 2013-12-05
3
538 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 109

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 109

Expert Comment

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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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 …

828 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