Solved

Javascript & php counter on click

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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 the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

803 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