Jump to content

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/243844-onclick/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/243844-onclick/#findComment-1252034
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/243844-onclick/#findComment-1252038
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/243844-onclick/#findComment-1252054
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.