physaux Posted October 10, 2009 Share Posted October 10, 2009 Hey guys, i am having another little problem... And here is what i am trying to do: I want to trigger a database count each time somebody clicks on a specific link, from my page. //The database coding isn't the problem So what i am missing is how do you detect the click of a link from your page with php? can you? Or would i have to link them to one of my "exit" pages and redirect them from that page to my external link, doing the database operation inside of the "exit" page? Any ideas? thanks! Link to comment https://forums.phpfreaks.com/topic/177231-tracking-a-click-from-your-page-how/ Share on other sites More sharing options...
Natefons Posted October 10, 2009 Share Posted October 10, 2009 hmm im not sure if theres a direct PHP method. but what you can do is use a "HACKISH" Javascript/PHP method for example: <a href="test.html" onClick="Javascript function">test</a> now create a javascript that has php inside of it. its hackish like i said,and is probably no way efficient. but its the first thing that came to my mind. Link to comment https://forums.phpfreaks.com/topic/177231-tracking-a-click-from-your-page-how/#findComment-934509 Share on other sites More sharing options...
Andy-H Posted October 10, 2009 Share Posted October 10, 2009 Javascript can't be used to trigger PHP code as PHP is parsed when the script is requested to generate the output whereas JS is client side and is triggered by events like onclick after the source has been sent, could be done with ajax or an increment once the page has redirected to the href. Maybe you could append a get variable to trigger the increment and create a file to include in your scripts? Link to comment https://forums.phpfreaks.com/topic/177231-tracking-a-click-from-your-page-how/#findComment-934512 Share on other sites More sharing options...
physaux Posted October 10, 2009 Author Share Posted October 10, 2009 Thanks guys but i think i figured it out. I'm using output buffering (i think) Here is what i have inside of a file called redirect.php I send people to redirect.php?redirect=URL <?php ob_start(); $language="EN"; require_once("includes/functions.php"); require_once("includes/constants.php"); require_once("includes/connection.php"); require_once(setlanguage($_SERVER['REMOTE_ADDR'])."/messages.php"); $canipclick = canIPclick($_SERVER['REMOTE_ADDR']); if($canipclick){ addclick($_SERVER['REMOTE_ADDR']) } require_once("includes/footer.php"); if($canipclick){ header( 'Location: '.$_GET["redirect"] ) ; }else{ header( 'Location: '.THISURL ) ; } ob_flush(); ?> I tested it and it seems to work for me. Anyone see any problems? Link to comment https://forums.phpfreaks.com/topic/177231-tracking-a-click-from-your-page-how/#findComment-934522 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.