Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Click counter

Status
Not open for further replies.

dbaseboy

Programmer
Apr 24, 2002
48
0
0
GB
Hi again!

Well Im slowly but surely working my way through this PHP and loving every minute however Im now trying to mix PHP with Javascript and hitting problems. Basically I have a PHP created page containing approx 40 external page links, what I need to do is update a counter in the table containing the details of the item they clicked.

eg

table - People (ID, Name, Link, Counter)

the 40 people are then listed in a table and if the user clicks the link they go to that persons page, what I want to do is update users Counter every time someone clicks their link (ie a referred to count). The way Id seen it would be to have an On_Click Javascript event which would then include a line of PHP to select the correct row in the table and update the counter eg

Code:
<script language="JavaScript">

Function UpdateLinkCounter()   {
<?php mysql_query('UPDATE `people` SET `counter` = `counter`++ WHERE CONCAT(`ID`) = $ID; ?> 
.....the Javascript to goto the correct link.
}

Im playing around with it but not having any joy, now Im hearing that you cant really embed php within Javascript which would explain a lot!

Does anyone have any ideas? Im sure this is pretty standard coding as per all those pay per click links etc.
 
Try having the links call your PHP page, which can update the database and redirect the browser to the actual destination.
 
so basically just a blank page which is passed the ID of the record to update and the link to then go to?

Brilliant! Theres me trying to do some Javascript and all the time its just an amendment of my "Add new record" script?

Thanks, I'll give that a go!
 
Blooomin heck!

I've got it to work at a fashion....however it inserts a record into the table along with many many more!

Heres my code....
Code:
$clickd = $_GET[clickd];
$sql="INSERT INTO `passedover` (`linkedurl`) VALUES ('$clickd')";
$result = mysql_query($sql) or die("Bad query: " . mysql_error());
echo "<META HTTP-EQUIV=Refresh CONTENT=\"5; URL=$clickd\">";
echo "<body>";
echo "Redirecting you to '$clickd'";

?>

The first time I ran it there were 10 records added to my original test record giving me 11 rows, only one of these 10 contained the URL the rest were blank. The second time I ended up with 164 rows!!!! of which 2 were correct.

Is it running a loop during the 5 second redirect? if so, can I just set that to zero?
 
ignore me!!!!

I forgot to close the connection so it was permanently adding records just most of them were blank.

Remember kids: always do a "mysql_close($whatever);"

;)
 
I have donated a star to you dbaseboy, for pointing out what many people fail to realise themselves.



______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Thanks for the star however I will donate it to anyone who can help me out on this now...

Nobody mentioned the fact that META REFRESH redirects dont show the referring URL in the receiving sites stats!

Something which is highly important for this project, can anyone help me out again? I need something to allow a nice simple counter update and redirect but shows in the stats.
 
Can you not use Header() to redirect, or is that just as bad?

failing that I'd bung a get request on like so:

echo "<META HTTP-EQUIV=Refresh CONTENT=\"5; URL=$clickd?from=YOUR_SITE_NAME\">";

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
can I just confirm that? are we saying that by adding the from= on the end it will ensure that the site receives the referring URL?

I've changed the code to something I read using Header() but one where its seen as a Code 301, seemingly thats supposed to work but I cant see any additions in the 2nd sites stats.

Daft question but if site2 is a subdomain of the same site as site1 will that not show up even though theyre on different Domain names?

in case I havent explained that properly, I own a large chunk of webspace under the domain of
Im now hosting a couple of sites which run as subdomains within that space ie you can get them at either or
so in this case, site1 is referring to site2.

Does that cause problems to the stats? am I asking this in the right forum? do I even know my own name anymore?
 
depends, you want to log the TARGET url ? or have the target site see where what the referring site(yours) is ?

If you want to have an image for a link to another site, the link intitially must be to a local page, so site1.com/refer.php?id=21


you then update mysql where id = 21 (counter+1)
select url from mysql where id=21, and refresh them on their way based on the url from the select.

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Yes on both however I have the logging bit working great, person clicks image, a href takes the user to a 2nd page with the URL of the required link which updates the database to show that link + 1 and redirects to the requested page. All that works fine (thanks to Igarner above) however its getting the linked persons site to recognise the fact someones come from mine. Basically its an ad listing site which will only keep the customers if they can see that people are visiting from mine.

 
how do they normally see this, dont they give you an affiliate id or link of some sort ?

If you add the $_GET request string, they'll be able to see its from you, but possibly not how they expect - it'll show in the logs very clearly but its possibly best to ask them how they want your references presented.

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
the sites im linking to arent affiliate type sites they are standard web sites that list with me to get promotion so most of them dont use PHP or anything, mainly basic HTML pages. So normally they would purely use the sites stats to see who was referring to them.

Its not real pay per click just that they need to see Im sending enough people to them to make it worth their while to continue advertising.

Strange thing is that until its sorted, Ive reverted back to standard <a href=...> code to ensure they get hits registering (figured that was more important at the moment than me seeing how many Id referred) yet the site thats also a subdomain of mine is still not registering any hits from my site (it is from others) even though I've clicked the link numerous times.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top