Jump to content

Ingolme

Moderator
  • Posts

    14,901
  • Joined

  • Last visited

  • Days Won

    177

Everything posted by Ingolme

  1. It's in the Javascript tutorial: http://www.w3schools.com/js/js_htmldom_css.asp
  2. The errors caused by Wordpress are only there if you install a theme that has errors in it. Since absolutely anybody can make themes for it there is the chance that you will install a theme that has invalid HTML. Do you have any Wordpress experience? Over 20% of websites on the internet use it, and knowledge of it is a highly valued skill in today's market, for better or worse.
  3. Ingolme

    <nextid>

    If you generate these with PHP or Javascrpt it should be easy to keep all the links up to date. The <nextid> element seems to be something completely different and unrelated to what you're asking for.
  4. You can't do that with HTML, but you can include the content using PHP. Most websites using PHP or an equivalent server-side language to put the same content in multiple pages.
  5. I would not diss Wordpress. I don't love it, but it's not a "defective product" by any means.
  6. You can see why it's not working by checking what mysql_error() returns. echo "post has not been published succesfully. Reason: " . mysql_error(); Your code is vulnerable to hacking. The mysql library is outdated and by passing POST data right into the query you're leaving it open to SQL injection. Here's an excerpt from the mysqli_error() manual page:
  7. There are two types of basic collision: Rectangular hit tests and circle hit tests. This game probably uses the circle hit test. In the circle hit test, your sprite object have an X coordinate, a Y coordinate and a radius: var circle = { x : 10, y : 10, radius : 5}; To check whether two circles are colliding, using pythagoras theorem to calculate the distance between the two. If the distance is smaller than the sum of their radii, then they are colliding: function collision(circle1, circle2) { var totalRadius = circle1.radius + circle2.radius; if(distance(circle1, circle2) <= totalRadius) { return true; } else { return false; }}function distance(circle1, circle2) { var xDist = circle2.x - circle1.x; var yDist =circle2.y - circle1.y; var hypotenuse = Math.sqrt(xDist*xDist + yDist*yDist); return hypotenuse;} That's as easy as I can put it.
  8. Actually, you only really need to store two states on that grid: empty or hit. You determine whether it hit a ship or not based on the ship positions and sizes.
  9. That's one way to do it. It's better to represent the states with numbers than with strings. For example: 0 = empty. 1 = miss, 2 = ship, 3 = hit ship. You would also need data structures for the ships to associate them with the grid. The model could contain an array of all the squares on the grid. For example, in a 5 by 5 grid the stricture could look like this: var board = [ 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 3, 1, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0]; Or like this: var board = [ [0, 0, 0, 0, 0], [0, 0, 2, 0, 0], [0, 0, 3, 1, 0], [0, 0, 2, 0, 0], [0, 1, 0, 0, 0]]; Each time the board changes, the view would loop through that array and find the corresponding table cell in the DOM and change its appearance. The controller would be the part of the program that changes the model and passes the model's data to the view.
  10. Ingolme

    Security

    Often a session will be destroyed when the IP address changed. You don't need to store the IP address in the database, just store it in the PHP session. If the session does not have an IP address stored then store the user's current IP address. If the session has an IP address in it then compare it to the user's IP address, if it is different then delete all data from the session and require the user to log in again. That's one way to prevent session hi-jacking.
  11. What value does "this" have in that context? You probably should just use the event object that's passed to the function instead: childTD[i].addEventListener("click", changeColor); function changeColor(e) { var element = e.target; element.style.backgroundColor="red";}
  12. Is that backtick next to @media in your actual code?
  13. <embed> is kind of outdated since it relies on external plug-ins. Sure, it's supported in HTML 5 but the <audio> element works much better.
  14. You already made a topic for this: http://w3schools.invisionzone.com/index.php?showtopic=54131
  15. $ptype is never equal to $allowed because one is a string and one is an array (or so I assume). In what part of the code is $ptype being set? If you want to check that a value exists in an array, then use in_array().
  16. This attempt at filtering, if it even works, will actually block out legitimate users. Some names actually have repeating sequences in them and are valid. The only thing you should try to filter is data that is not good for the system, such as an empty field or attempts at code injection; otherwise you risk losing real clients. If you want to stop robots, try the honeypot technique. This technique involves putting an invisible form field on your page with something generic such as "name" or "email" but making it invisible. If the field is filled in then you know a robot did it, because humans can't see that field.
  17. Ingolme

    Security

    Yes, anytime the user wants to change their password they should have to input their old password. This way, if somebody gets into the account through session hi-jacking they can't lock the user out of their own account. The same goes for e-mail, because the e-mail can be used to send account recovery information. It's preferable to use HTTPS for login. If you're managing sensitive information such as credit card numbers, home address or personal identity information you absolutely must use HTTPS. Testing for security issues is complicated. A large company would hire a professional hacker (ethical hacking is actually a job). Asking for them to confirm their e-mail address is not a security issue, it's more to protect the user from human error. If they put their e-mail address wrong then they'll never get an activation e-mail or recovery e-mail from the website.
  18. I don't think that there is actually a standard way to do that. selectedIndex is a property of the <select> element, which makes a dropdown show up on the page. If you have a dropdown you can access the selected value with its value property, or you can access the <option> element by using the options[] property. var sel = document.getElementsByTagName("select")[0];alert(sel.value);console.log(sel.options[sel.selectedIndex]);
  19. According to the MDN, the volume attribute is not supported by any browser: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio#Browser_compatibility It seems that you can use Javascript to modify the volume property of the element, though: https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/volume
  20. I would make that profile in HTML, then use Javascript to show it, position it and change the content within it.
  21. The syntax you're using is non-standard and very old. Learn DOM methods to access elements: http://www.w3schools.com/js/js_htmldom.asp For a list of radio buttons something like this would work: <div id="radio-buttons"> <label><input type="radio" value="1"> Something</label> <label><input type="radio" value="2"> Something else</label></div> Now you can use DOM methods to get to to radio buttons and check whether they're selected or not. var radioButtons = document.getElementById("radio-button").getElementsByTagName("input");for(var i = 0; i < radioButtons.length; i++) { if(radioButtons[i].checked) { // Do something here with the radio button that is currently selected alert(radioButtons[i].value); }}
  22. Just loop through the string. Much better and more efficient than a regex for this case. The logic would be this: Set counter to zero Loop through the string For each letter in the string - If the letter is the same as before, add 1 to the counter - If the letter is different than the one before then set the counter to zero If the counter is greater than five set a flag to indicate that the string is invalid.
  23. Object property names are technically strings to begin with. There's no difference between {"x": 1} and {x: 1} In JSON, the property name actually requires double quotes. If you want to be able to pass a variable string as an object property, the square brackets will do it. var position = { x : 1, y : 2}var axis = "x";alert( position[axis] ); // Displays "1"
  24. I wouldn't advise putting content in the CSS. The page's content should be accessible when the CSS is not available. But text being centered or not has nothing to do with how readable it is. As for background images, they aren't needed. If your image is a relevant part of the content then use an <img> tag. But as for formatting and layout, that's unrelated to the page's content and should be handled by CSS. There's no need for text color, element positioning, font size, background colors and such to be in the HTML.
×
×
  • Create New...