Solved

Javascript & php counter on click

Posted on 2013-12-05
3
546 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 110

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 110

Expert Comment

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

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
This article discusses four methods for overlaying images in a container on a web page
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)
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 …

624 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