View Full Version : Include PHP onClick

11-30-2010, 09:46 PM
Hi there,

*I recommend checking this small schematic about the problem: http://www.imageupload.org/?di=13129114988015

I have a small question due to the fact that I only have moderate knowledge of PHP and JavaScript.

Currently I have one PHP file containing every content of my site, they are all getting called with the include function.

Problem is they are getting loaded even if the user doesn't click on the link; they get visible with JavaScript only when you click on the link.

I do not have any performance or organisation issue, but my main problem is due to the fact that Google Analytics can't record that anyone clicked on a specific link because they are all on the same page.

So, my solution is to add the Analytic code to each PHP include file and load them each time the user clicks!

Is it possible and how can I do this?!


11-30-2010, 09:57 PM
Can't be done with PHP.
Look into using AJAX to call only the pages necessary. The extend of PHP for this is querystring handling, and thats all. PHP cannot interact with a browser, and therefore an onclick event will never fire.

11-30-2010, 09:59 PM
Look into AJAX as this will allow Javascript and PHP to communicate and it will tell the Javascript to only include when the button is clicked.

11-30-2010, 10:09 PM
Ouch....... I have ZERO experience with AJAX....

11-30-2010, 10:13 PM
Well my main problem is Analytics, cant I just do something to make it work so it can detect the pages witch the current architecture? The links to the other pages work with A HREF="#page1". Or can't I just do it in JavaScript ?

11-30-2010, 10:24 PM
Those are all JS/HTML issues. I don't know a thing about how the google analytic's work I'm afraid, but other than not having the content on your page I don't know how to stop it. Someone else may have some better ideas, but I don't think you can resolve this with PHP.
PHP cannot make use of a hash on a url, but it can make use of a querystring to determine what to show.

11-30-2010, 10:25 PM
Aiight! Well Analytic work but puting a JScript on each page that gets loaded so.... I'll try to look onto AJAX.. if anyone else has any idea ?!

11-30-2010, 10:28 PM
AJAX sounds the best to me.
Its a piece of cake to use, just takes some practice of dom traversing. If the links are already there to show something, it won't be difficult to alter it to use the ajax to load the data instead.