Jump to content

Counting amount of times a javascript link has been opened in PHP


franzy_pan

Recommended Posts

Hi,

 

Ok, this is the problem ... i need to figure out how to count the amount of times that a JavaScript link has been opened in PHP (the count being in PHP not Javascript).

 

The page is called from a Javascript function, like so: <a href="javascript:openlink();">

 

and the function is stored inside a .php file:

 

function openlink(){

theWin = window.open("http://www.??.co.uk/player/player.asp", "newstream", "width=600,height=467,top=100,left=100,scrollbars=no,center=no,location=no,toolbars=no,status=no")

theWin.focus;

}

 

i need to count how many times this link has been opened.  I need the count to be in PHP as the information will then be stored in a MySQL database.

 

I know that ordinarily if it was just a page open in Javascript using

 

window.location.href = "http://www.??.co.uk/default.php"

 

i could just add variables to the end of the url and pass this variable to a php script using $_GET ... but the use of the function is confusing me.

 

I hope this explanation is good enough ... if not just let me know.

 

Thanks in advance :-)

 

Franzy Pan

I should have said before ... if this can't be done the way i'm suggesting is there anyway of counting the amount of times a link has been opened from a javascript function?

 

Any help that can be provided will be appreciated.

 

Thanks again

 

Franzy Pan

I don't know if it would work or not, but how about something such as

<?php 
   global $count; $count = 0;
?>
...
function openlink() {

   <?php $count++; ?>
   ...

   window.status = <?php echo $count; ?>
}

or maybe just

function openlink() {
   <?php
      ...
      mysql_query("update tbl_name set ...");
      ...
   ?>
   ...
}

 

HTH

^that wouldn't work. You're implying that you can run PHP code when calling a JS function, which you can't do. When the page loads initially, all PHP code is converted to text/html output, so it would try and write something to the database when the page loads, not when the JS function is called.

One possibility is to use AJAX, ie call an external PHP script from the JS.

 

You should do any counting from the page that is opened, ie "http://www.??.co.uk/player/player.asp" - it's possible to link through to a MySQL database with ASP.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.