franzy_pan Posted September 30, 2008 Share Posted September 30, 2008 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 Quote Link to comment Share on other sites More sharing options...
franzy_pan Posted September 30, 2008 Author Share Posted September 30, 2008 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 Quote Link to comment Share on other sites More sharing options...
shutat Posted September 30, 2008 Share Posted September 30, 2008 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 Quote Link to comment Share on other sites More sharing options...
svivian Posted September 30, 2008 Share Posted September 30, 2008 ^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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.