Solved

Javascript & php counter on click

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

895 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

16 Experts available now in Live!

Get 1:1 Help Now