Jump to content

penisland

New Members
  • Posts

    4
  • Joined

  • Last visited

Everything posted by penisland

  1. I would like to know how to call a php function using javascript. I've done some googling and found that I need to use ajax. I read some tutorials and don't understand how to use ajax. All I want to do is execute a php function, which writes to a txt file, from the execution of a javascript function. I don't care if the webpage refreshes or not; I'll just make the javascript function refresh the page. Something like this: <?php include 'banusers.php'; ?> <script> function banUser() { <?php writeIPToFile(); ?> alert("You have been banned!"); window.location.reload(); } </script> <p>Click <a href="javascript:banUser();">HERE</a> to ban yourself!</p> Would someone be kind enought to write an example for me? Edit: fixed typo
  2. 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
  3. I have a .txt document named bannedIPS.txt that has this in it: 12.326.25.3 192.168.1.1 207.236.2.32 10.218.24.5 and then my php script has this //Gets user's IP $ipaddress = $_SERVER['REMOTE_ADDR']; //List of IPs to block $fh = fopen('UserIP/bannedIPS.txt','a+'); $ipBlockList = array(); $countWhileLoop = 0; while($line = fgets($fh)) { $ipBlockList[$countWhileLoop] = $line; $countWhileLoop++; } fclose($fh); //Determine if user IP is on the list for($i=0; $i<=$countWhileLoop-1; $i++) { //Debug for seeing what $ipBlockList[$i] is echo $ipBlockList[$i]."<br/>"; if($ipaddress==$ipBlockList[$i]) { echo "banned"; exit; } } My IP address is 207.236.2.32 so it should display: 12.326.25.3 192.168.1.1 207.236.2.32 banned but it displays: 12.326.25.3 192.168.1.1 207.236.2.32 10.218.24.5 so, the if statement isn't getting triggered. Why is that? I'v tried: if($ipaddress=="207.236.2.32") { echo "banned"; exit; } and then it works, but if it's the variable, it doesn't. PS. I just started learning PHP today from W3Schools and Google. Edit: Fixed typo
×
×
  • 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.