NYCPHP Meetup

NYPHP.org

[nycphp-talk] javascript calling php function -- now question on Ajax

Susan Shemin susan_shemin at yahoo.com
Tue Feb 19 14:10:55 EST 2008


The most direct answer to my question ended up in my spam folder!  Because subsequent emails referred to Austin's reply, I went hunting for it, and there it was in spam.

I'm into keeping programming as simple as possible except where a more complex solution is warranted, and this is workable.

Thanks for all your replies!

Susan


----- Original Message ----
From: Austin Smith <asmith at observer.com>
To: NYPHP Talk <talk at lists.nyphp.org>
Sent: Monday, February 18, 2008 10:34:13 PM
Subject: Re: [nycphp-talk] javascript calling php function -- now question on Ajax

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>

 




-----Inline Attachment Follows-----

_______________________________________________
New York PHP Community Talk Mailing List
http://lists.nyphp.org/mailman/listinfo/talk

NYPHPCon 2006 Presentations Online
http://www.nyphpcon.com

Show Your Participation in New York PHP
http://www.nyphp.org/show_participation.php
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20080219/41e1ff7d/attachment.html>


More information about the talk mailing list