I have this html code in a .php document:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<?php
include 'UserIP/ipFunctions.php';
//Logs client's IP
logIP();
//List of and invokes banned IPs
bannedIPs();
?>
<title><?php print "Your IP address is ". $_SERVER['REMOTE_ADDR'];?></title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script>
<script type="text/javascript" src="script.js"></script>
<link rel="stylesheet" type="text/css" href="main.css"/>
<script>
function banUser()
{
<?php addIPToBannedList(); ?>
alert("You have been banned!");
window.location.reload();
}
</script>
<script>
$(function() {
$( "#dragable" ).draggable();
});
</script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-39055717-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body>
<div id="banner1">
<a href="http://www.brevin.com/lawless"><div id="banner"></div></a>
</div>
<div id="main">
<h1 id="main_heading">Welcome to Brevin.com, Jim</h1>
<p id="notUsername">Not correct name? Click <a href="javascript:resetUsername();">HERE</a> to change</p>
<p id="notUsername">Do you want to get banned from Brevin.com? Click <a href="javascript:banUser();">HERE</a> to ban yourself!</p>
<div id="pixel"></div>
<div id="dragable" class="ui-widget-content">
<img src="tubaland.jpg" width="792" height="612" />
</div>
</body>
</html>
I have a link (line 59) that calls a JS function banUser(). It will do what I want to when I click the link, but the PHP code (line 26) gets excecuted on page load. I only want it executed when I click the link. How would I do that.
Edit: Added line numbers