voip03 Posted August 4, 2011 Share Posted August 4, 2011 Before onclick the function call() is calling ? Why TIA <? session_start(); require("config.php"); //LOGGED IN ID VALIDATION - Only registered user Access ! if(isset($_SESSION['SESS_LOGGEDIN'])== FALSE) { header("Location:".$config_basedir."login.php?error=2767"); } ?> <script type="text/javascript" > function downloadPdf(el) { var iframe = document.createElement("iframe"); iframe.src = "download/itil.zip"; iframe.onload = function() { // iframe has finished loading, download has started el.innerHTML = "Download"; } iframe.style.display = "none"; document.body.appendChild(iframe); } </script> <? function call() { //get ip address... if(!empty($_SERVER['HTTP_CLIENT_IP'])) { // share internet $ip=$_SERVER['HTTP_CLIENT_IP']; $ip .= "/S"; } elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { // pass from proxy $ip=$_SERVER['HTTP_X_FORWARDED_FOR']; $ip .= "/P"; } else { $ip=$_SERVER['REMOTE_ADDR']; $ip .= "/O"; } $sql = "INSERT INTO downloadUserIP( date, userID, ProductID,IP ) VALUES ( NOW(),'".$_SESSION['SESS_USERID']."','".$a."','".$ip."');"; $res = mysql_query($sql); if(!$res) { die(" Could not query the database customers 24 : <br/>". mysql_error() ); } $_SESSION['SESS_GUEST_IP'] = mysql_insert_id(); echo "ok"; } ?> <br/> <a href="download/ECDL.zip" onclick="this.innerHTML='<? call(); ?>'; downloadPdf(this);">Download</a> Quote Link to comment https://forums.phpfreaks.com/topic/243844-onclick/ Share on other sites More sharing options...
IrOnMaSk Posted August 4, 2011 Share Posted August 4, 2011 Really? Quote Link to comment https://forums.phpfreaks.com/topic/243844-onclick/#findComment-1252029 Share on other sites More sharing options...
voip03 Posted August 4, 2011 Author Share Posted August 4, 2011 Quote Link to comment https://forums.phpfreaks.com/topic/243844-onclick/#findComment-1252030 Share on other sites More sharing options...
gizmola Posted August 4, 2011 Share Posted August 4, 2011 Because PHP is serverside, not clientside. Javascript is clientside. The only way you can have functionality like this (call a serverside script based on a a clientside (javascript) event occurring) is to implement the serverside functionality in a seperate script that you make an ajax call to using a get or post method. Quote Link to comment https://forums.phpfreaks.com/topic/243844-onclick/#findComment-1252034 Share on other sites More sharing options...
voip03 Posted August 4, 2011 Author Share Posted August 4, 2011 onclick can I call serverside code? Quote Link to comment https://forums.phpfreaks.com/topic/243844-onclick/#findComment-1252036 Share on other sites More sharing options...
gizmola Posted August 4, 2011 Share Posted August 4, 2011 Yes, so long as the onclick makes an ajax call. Ajax is not the simplest thing to do in a cross platform manner. I'd suggest using jquery to make it simpler. See http://api.jquery.com/jQuery.get/ for an example of how to use jquery to make a get request to a url. Quote Link to comment https://forums.phpfreaks.com/topic/243844-onclick/#findComment-1252038 Share on other sites More sharing options...
ManiacDan Posted August 4, 2011 Share Posted August 4, 2011 voip, please don't report a post because a mod has moved it. You are not understanding the basics of client-server web programming. Read carefully: PHP - PHP is a server-side language that only executes on the SERVER. It can only run code on your server, and cannot run code on the client. A PHP page will execute entirely and then die before ANY content is shown to the user. JavaScript - JavaScript is an entirely separate language. Read that again. JavaScript is a programming language that has nothing to do with PHP. It is interspersed into HTML code for convenience. It runs on the CLIENT machine. It cannot run on your server. Any javascript on your page executes AFTER the PHP is already dead. JavaScript can trigger FURTHER PHP events, but they do not run in tandem. Your problem is that you want something to happen when the user clicks. This can be accomplished in two ways: 1) Reloading the page entirely by pointing it to a new URL. This is not what you want, but this is the default behavior for clicking a link. 2) Trigger the onClick javascript even, in javascript, on the client's machine ONLY. This has the capacity to call PHP scripts through AJAX, but you must use javascript to perform client-side operations. Now, given this information, continue the discussion. And as a side note, for the love of god use complete sentences and real words. The quality of help you receive is directly proportional to how easy your posts are to read. See how mine is all spelled correctly and the sentences are complete? -Dan Quote Link to comment https://forums.phpfreaks.com/topic/243844-onclick/#findComment-1252054 Share on other sites More sharing options...
IrOnMaSk Posted August 4, 2011 Share Posted August 4, 2011 And as a side note, for the love of god use complete sentences and real words. demonstration: "I ain't gotcha" Quote Link to comment https://forums.phpfreaks.com/topic/243844-onclick/#findComment-1252078 Share on other sites More sharing options...
voip03 Posted August 4, 2011 Author Share Posted August 4, 2011 IrOnMaSk thank u Quote Link to comment https://forums.phpfreaks.com/topic/243844-onclick/#findComment-1252083 Share on other sites More sharing options...
voip03 Posted August 4, 2011 Author Share Posted August 4, 2011 When I am writing a story; I would do that! Thank u ManiacDan . Quote Link to comment https://forums.phpfreaks.com/topic/243844-onclick/#findComment-1252085 Share on other sites More sharing options...
ManiacDan Posted August 4, 2011 Share Posted August 4, 2011 You* Seriously, this is a technical forum for professionals and amateurs in a highly skilled and educated field. It's not a text message to your friends. That kind of typing will get some people to actively antagonize you. Quote Link to comment https://forums.phpfreaks.com/topic/243844-onclick/#findComment-1252087 Share on other sites More sharing options...
voip03 Posted August 4, 2011 Author Share Posted August 4, 2011 ManiacDan ! which part is look like text to you? Quote Link to comment https://forums.phpfreaks.com/topic/243844-onclick/#findComment-1252089 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.