PHP tutorial errors

Home Forums Bugs PHP tutorial errors

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #1405
    Geraldo Sulka
    Participant

    Time: [18:48]

    -Problem:

    Typed content was displayed as raw HTML in the browser, meaning the server wasn’t processing it correctly.

     

    Cause:

    The URL being accessed might have been a local file path (like file:///C:/xampp/htdocs/index.html), which bypasses server-side processing (e.g., PHP).

     

    Fix:

    [19:09]

    Replaced everything before htdocs with localhost (e.g., http://localhost/index.php). This tells the browser to request the page through the local web server (like Apache), allowing PHP or other server-side scripts to run

    -What might look like an error

    In the text area, there are 3 lines of random letters, all showing in red font color.Normally, text entered into a <textarea> doesn’t have red text unless there’s a style applied or an error handling system that marks invalid or problematic input.

    What could be causing the red text (possible error sources):

    -CSS Styling:
    There might be CSS applied (like .error { color: red; }) that’s affecting the text in the <textarea>—maybe unintentionally.
    Check if there’s a style.css or inline CSS that changes the text color inside the <textarea>.

    -Form Validation Feedback:

    If your PHP script is validating input and finds an error (e.g., bad words, too short, or missing something), it might highlight the invalid text in red to signal a problem.

    But in that case, you’d usually also see an error message (like “Text cannot be empty!”)—which is missing here.

    -Browser Auto-fill or Highlighting:
    Some browser plugins (or dev tools) highlight certain text fields in color, but that’s less likely here.

     

    -HTML Issue:
    If, after submitting, you’re echoing the text back into the <textarea> and it’s not properly escaped, it’s possible that some tags (like <font color=”red”>) are being inserted into the HTML and messing up how the text looks.

    -The error being explained at in the video is a cross-site scripting (XSS) vulnerability.

    Here’s a breakdown of what that means and why it’s an error:

    · The Scenario: The video is discussing a situation where user-generated content (like comments or posts) is displayed on a website.

    · The Threat: If the website doesn’t properly handle this user input, malicious users can inject JavaScript code (or other client-side scripts) into their posts.

    · The Consequence: When other users view this post, their browsers will execute the injected JavaScript code. This malicious code can then perform various harmful actions, such as:

    o Stealing sensitive information: Cookies, login credentials, personal data.

    o Redirecting users to malicious websites.

    o Modifying the content of the page they are viewing.

    o Displaying fake login forms to capture passwords.

    o Performing actions on the user’s behalf without their knowledge.

    Why is this an error?

    It’s a significant security flaw because it allows attackers to compromise the security and integrity of the website and potentially harm its users. A well-designed website should always sanitize user input before displaying it to prevent the execution of unintended or malicious code.

    The Solution (as mentioned around):

    The video likely goes on to explain that using the htmlspecialchars() function in PHP is a common way to mitigate this error. This function converts special HTML characters (like <, >, &, “, ‘) into their HTML entities. By doing this, any potentially malicious HTML or JavaScript code is treated as plain text and displayed as is, rather than being executed by the browser.

    In essence, the error at is the lack of proper handling of user input, leading to a vulnerability where malicious scripts can be injected and executed in other users’ browsers. This can have serious security and usability implications for the website and its visitors

     

    • This topic was modified 6 months, 3 weeks ago by Geraldo Sulka.
Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.