If someone clicks then

Namecheap AuctionsNamecheap Auctions
Spacemail by SpaceshipSpacemail by Spaceship
SpaceshipSpaceship
Watch

thetzfreak

Established Member
Impact
19
What code would this be? I want some code to be executed if someone clicks on a certain link. So it would be something like

$x = 0
if (someone clicks on this link);
{
$x = $x +1;
}
echo "$x";

Basically, if someone clicks, the number goes up.

I was told this could be done easily with javascript. Can someone help me by giving me this javascript code?

Thanks.
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Unstoppable Domains — AI StorefrontUnstoppable Domains — AI Storefront
I'm not sure how to do it with javascript but I'm assuming that you are refering to a type of counter (click tracking). In which you are going to have to store the variable $x either in a flat file or a database. Otherwise $x will equal 0 everytime the page is refreshed.

If you'd like help with doing in PHP then I can lend a hand.
 
0
•••
i'm no expert, but assuming you wan't the link to actually take you somewhere, you only have two options, create a cookie, or add a variable to the end of URL ex.

before:
www.example.com

after:
www.example.com/?variable=111

the ending won't effect anything about the page

you can retrieve the variable on the next page with the javascript:
variable = window.location.search.substring(1);

which will return
variable = 'variable=111'- this is a string, you'd have to extract the number somehow and set it to the variable all over again

as for the link part, you could set it up so:
<a href="#" onclick="somefunction()">

somefunction might be:
function somefunction(){
variable = variable + 1
window.location='www.example.com/?variable='+variable
}

hope this helps-
i'm sure there are plenty of 'better' ways, but i've found this to be fairly simplistic
 
0
•••
What you want is ususally referred to as link/click tracking. You'll need both PHP (or another server side language) to do this. Google it, there are plenty of these scripts.
 
0
•••
Another thing u can do is make a txt file and make +1 the number on it and then display the number
 
0
•••
0
•••
DomainEasy: white label portfolios are live. Enable yours.

We're social

Escrow.com
Spaceship
Escrowly
CryptoExchange.com
Domain Recover
URLs.com
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back