Jump to content


  • Posts

  • Joined

  • Last visited

  • Days Won


Everything posted by justsomeguy

  1. Because by the time that event handler runs, i is set to something else. It doesn't use the value that i had when you assigned the event handler, it uses the current value of i, whatever that is. You can use a closure to pass i as a new variable and use the value of that instead. var i; for (i = 0; i <= correctEls.length; i++) { correctEls[j].addEventListener("click", (function(idx) { return function() { whenCorrectClicked(idx); } })(i)); i++; } Now that makes an anonymous function that executes immediately (IIFE), which you pass the value of i, and inside the function it uses idx for the parameter. The IIFE returns a function which uses the value of idx, that returned function gets assigned as the click handler.
  2. It would be more efficient for lookups to only store the list of the blocked IPs, the list of all IPs could be retrieved from the IP column in the posts table. Again, some forums also choose to store which IPs an account was created with or at various other points (account activation, login, etc). As an admin I can see the IP on every post here, for example, and can use some tools to see all of the activity associated with a certain IP, like which users posted using it or who registered an account using it. The list of blocked IPs should be its own table only listing those that are blocked, because it's going to need to be looked up fairly frequently and you'd want to keep that as small as possible.
  3. You can find the user's IP address and other information in the $_SERVER array: https://www.php.net/manual/en/reserved.variables.server.php
  4. An IP address blacklist is one option, although it's not difficult to get around it. Most forums will record the IP address any time someone creates an account, posts a message, etc, and then there are tools to look up how a particular IP address has used the forum and things to maybe require admin approval for a certain IP or just block them entirely. The first step is saving the IP when people use your site, and then you can build the other tools that use the IPs.
  5. Add a return statement before the recursive call. You want to return the value of the recursive function.
  6. That's a pretty vague question. And why are you trying to define a function within another function?
  7. Try it and see what happens. You can use array indices with a string to access different characters of it, e.g.: $string = 'some string'; $string[4] = '-'; echo $string; But you're trying to use an array index which is a string: $string = 'some string'; $string['r'] = '!'; While it shouldn't be hard to figure out which character in that string is in the 4th position, it doesn't make much sense to try and figure out which character is in the rth position.
  8. Because you're trying to access or set things like $result['rgb']['r'], where $result['rgb'] is a string. You probably meant to make it an array instead of a string.
  9. Like most programming languages, there's documentation: https://groovy-lang.org/documentation.html https://groovy-lang.org/api.html
  10. It looks like captcha_sa is already a global variable, so just set it with the new value.
  11. Have a global object or something where you can save properties or methods that should be usable by anything.
  12. The browser doesn't care what the filename is, just make sure it's right: <script type="application/javascript" src="image.jpg"></script> The browser isn't going to complain about an extension, have you ever seen an error message like that? It's going to download the file you tell it to and treat it like you're telling it to treat it, the browser assumes that the programmer knows what they're doing. If the file has an extension that PHP is configured to handle, then when your browser sends a request for the file the web server will send it to PHP and send the output to the browser, like with any other request. It's not a security problem, just efficiency. There's no reason to have PHP try to parse a bunch of file types that will almost never have PHP code in them. I just use .js.php when I want to indicate a PHP file that should output Javascript. That's what it's for.
  13. Requesting a Javascript file isn't going to run any PHP code unless the web server is configured to send .js files to PHP. You could name the file with a .php extension if you need to dynamically create Javascript code for whatever reason.
  14. If you use include_once or require_once to include files in PHP then it will only include the same file once even if there are multiple include statements. Hopefully you have a main PHP include file that your other PHP files include that defines various global functions and variables, and that would be the place to include any file that you want available on any other page.
  15. You can either submit the form, get the form values with PHP, query the database, and show a new page with a new form with the data, or use Javascript to send an ajax request to PHP to get the database results and then display them on the page again.
  16. I don't think I understand your question. You've designed a class but you don't know how to use the class you've designed?
  17. Any database supports multi-user access, the database will let several different applications connect at once. I don't know what you mean, what are you saving? That's what a database is for. Have page to update the header text in the database, and the other pages should get the text from the database and display it.
  18. It might depend on your environment. If you're using Microsoft servers with .NET on the backend, then you might have SQL Server available. If it's a server with PHP on the backend then MySQL/MariaDB would be most popular.
  19. You can use a single query with a join, you only need to use recursion if the replies can be nested under each other. If it only shows one record from the database then there's probably an error. mysql_query does not show errors from MySQL, you need to check and display them yourself. The entire mysql extension is also removed in the current version of PHP, I would suggest switching to PDO or mysqli.
  20. This forum is not your code writing service, we are here to teach people how to do it themselves. If you want the two events on the same element then put the two events on the same element.
  21. If replies are only nested one level deep then using a join would let you get everything with a single query. Otherwise you need to put the second query in the loop for the first, and that's going to cause problems with scaling if you need to run 200+ queries to show that page.
  22. Javascript running in a browser only has access to the current document. Trying to do anything else would be a series of hacks. You could put a bunch of hidden iframes or something on the page to point to different pages if they're on the same domain and try to access things through that. A much simpler and more useful solution would be to store your data in a database instead of in HTML files. Depending on what the purpose is, you can save the various values in localStorage or sessionStorage to access on other pages.
  23. You save the return value from setTimeout, and use clearTimeout to cancel it. obj.src = obj.src + "?" + Math.random(); That's going to produce something like this: /home/tux/Prog/Medias/Images/calib1.png?123?456?789?... A URL shouldn't have more than 1 question mark.
  24. SQL doesn't have a way to say "group by every 6 months", you just have to explicitly tell it what you want.
  25. What specifically happens or doesn't happen when you submit that? Are there error messages?
  • Create New...