Id like to create a script that shows how many times a link has been clicked on my site
Is there a way to do this via PHP/MySQL?
Any tutorials/examples??
16 replies to this topic
#1
Posted 20 March 2011 - 03:04 PM
|
|
|
#2
Posted 20 March 2011 - 03:45 PM
make a javascript or php function that is executed by the onclick attribute that you put in your <a> tag.
PHP is good for if you want to store this count in a database
Javascript is if you want to work on the client computer
JavaScript and HTML DOM Reference <- that is w3schools's section on Javascript
PHP is good for if you want to store this count in a database
Javascript is if you want to work on the client computer
JavaScript and HTML DOM Reference <- that is w3schools's section on Javascript
#3
Posted 20 March 2011 - 11:26 PM
Yes, an javascript is one option. the other option is to use what for example facebook uses, a middlepage that takes the url as a parameter and then makes a header("Location") to let the user be directed to the correct url, while the middlepage itself does the statistics.
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall
I study Information Systems at Karlstad University when I'm not on CodeCall
#4
Posted 21 March 2011 - 12:27 AM
Any example code I could use for this?
I'm not THAT experienced with PHP as I am still learning.
So what you're saying is, the Link would be pushed to the middle page, where it would then carry out a function to count that statistics, and then direct them to the actual page?
I'm not THAT experienced with PHP as I am still learning.
So what you're saying is, the Link would be pushed to the middle page, where it would then carry out a function to count that statistics, and then direct them to the actual page?
#5
Posted 21 March 2011 - 02:36 AM
Yes, more or less. Usually, you prefixes the actual link with your middelpage so you write:
in your code then, you do something like this:
<a href="l.php?url=http://www.microsoft.com">Microsoft</a>in your HTML. this calls l.php (facebook calls this l.php, so I used them as example. you can call it whatever you like of course) with the actual url as a parameter.
in your code then, you do something like this:
<?php
$link = $_GET['url'];
header("Location: $link");
// here you do your database stuff so you count the link click
// for example, you can store referring url, so you know what page they clicked the link on and whatever you like.
?>
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall
I study Information Systems at Karlstad University when I'm not on CodeCall
#6
Posted 21 March 2011 - 02:54 AM
I see, and then in order to count the visits I could use a simple MySQL insert and +1 to whatever number was in the field in the SQL table to begin with?
I need the links to be friendly to Spiders/Crawlers, would using this kind of URL still be able to create all important Backlinks to sites or would it make the link unfriendly to spiders and search engines etc?
I need the links to be friendly to Spiders/Crawlers, would using this kind of URL still be able to create all important Backlinks to sites or would it make the link unfriendly to spiders and search engines etc?
#7
Posted 21 March 2011 - 04:35 AM
the link would not be so friendly I guess, but that's not within my knowledge area. an OnClick event on the link throwing an ajax request to a php script would probably be better for Spiders...
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall
I study Information Systems at Karlstad University when I'm not on CodeCall
#8
Posted 21 March 2011 - 05:08 AM
Thinking about it I doubt there would be any easy way to make it spider friendly.
Unless it would be possible to remove the l.php? via a htaccess MOD_REWRITE function?
Unless it would be possible to remove the l.php? via a htaccess MOD_REWRITE function?
#9
Posted 21 March 2011 - 05:19 AM
you could of course make a subdir /link/http://... instead but you still have a call to your server first which can make trouble in seo
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall
I study Information Systems at Karlstad University when I'm not on CodeCall
#10
Posted 21 March 2011 - 05:28 AM
Yeah, I think there's proably going to be an issue with this completly, I'm sure there would be a workaround.
Thank's for your input!
Thank's for your input!
#11
Posted 21 March 2011 - 08:15 AM
Plain Text code - 11 lines - codepad
I really don't see why you would link like explained in this thread, other than doing the example I posted above
I really don't see why you would link like explained in this thread, other than doing the example I posted above
#12
Posted 21 March 2011 - 08:21 AM
That was looks interesting, is it Javascript or PHP, is the OnClick event a.
Does OnClick within the Hyperlink require any Javascript/PHP Tag Openers/Wrapping or would that just work 'Out-the-Box'
Does OnClick within the Hyperlink require any Javascript/PHP Tag Openers/Wrapping or would that just work 'Out-the-Box'
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









