[nycphp-talk] javascript calling php function -- now question on Ajax
Austin Smith
asmith at observer.com
Tue Feb 19 01:34:13 EST 2008
Not to discourage you from using xAjax, which I've seen put to fine use, it
seems to me like you're adding Javascript where PHP would do the job just
fine, all by itself. Assuming that your anchor element is really going to
direct the user off the page, you might do well to implement something like
this:
<a href="redirect.php?website=http://www.nyphp.com&link=nyphp">NY PHP</a>
Then redirect.php would be the contents of your aforementioned code. You'd
also have to call your capture_click function yourself in the PHP code with
your two GET variables as arguments--and be sure to run them through
mysql_real_escape_string.
Plenty of sites use this method to track clicked links off-site, especially
when they monetize their clicks.
Have you considered a simple solution like Google Analytics? I'm no web
stats/SEO guru, but our sales and marketing people like it a lot... and it's
free.
Hope that helps a bit.
Austin
On Feb 18, 2008 11:58 PM, Susan Shemin <susan_shemin at yahoo.com> wrote:
> thanks, Mike and Ken
>
> first off, I'm not using a form (so no POST); the link is in an anchor
> tag. I could put a form around it, but that seems to me making a simple
> link complex.
>
> I want to run this php code when the link is clicked
>
> $webpage="";
> $link_clicked="";
>
> Function capture_click($webpage,$link_clicked)
> {
> $entry_date=date("m-d-y-H-i");
>
> $sql = "INSERT INTO click_details " .
> "SET webpage='$webpage', link_clicked='$link_clicked',
> entry_date='$entry_date'";
> $ok = mysql_query($sql);
> if ($ok) {
> //error checking
> }
> }
> ?>
>
> and then the anchor text (or how I guessed would work)
>
> <a href=www.nyphp.org onclick="<?php
> capture_click(name_of_my_webpage,link_name); ?>";>info on PHP</a>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20080219/9eaaa21b/attachment.html>
More information about the talk
mailing list