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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

^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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.