+ Reply to Thread
Results 1 to 9 of 9

Thread: PHP remove html/other uncessary tags? - need help

  1. #1
    a-a-a is offline x10Hosting Member a-a-a is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    20

    PHP remove html/other uncessary tags? - need help

    Not sure if this is the right place. But..
    How do remove html/other uncessary tags in php? Do I use strip tags? I've read tutorials, but I don't know how to apply it to my script.

    Basic idea of my script: (actual script is too long to post it all)
    First, it is an html form for the user to enter a 'short message'.
    It gets compared with the 'correct message' (using php if/else), and if it's right, they get redirected elsewhere.
    And I have several pages set up like this, with many different variables in total.

    I've read that you shouldn't trust what the user inputs, so I want to make my script safer. How do I make the input part safer? (The entered 'short message' should only contain letters and numbers. Nothing else.)
    I think I have to use strip tag, but I don't really know how or where to use it.

    Help is appreciated. Thank you.

  2. #2
    engel is offline x10Hosting Member engel is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    54

    Re: PHP remove html/other uncessary tags? - need help

    I think that htmlspecialchars() will do what you're looking for. If the user enters any HTML or PHP or anything that shouldn't be there, the characters like < and > are changed to &lt; and &gt; respectively (?). This will prevent most chances of attack, as you need to use these characters to initiate PHP and to use any tag in HTML.

  3. #3
    Slothie's Avatar
    Slothie is offline Lord Of The Keys Slothie is an unknown quantity at this point
    Join Date
    Sep 2007
    Location
    Singapore
    Posts
    1,432

    Re: PHP remove html/other uncessary tags? - need help

    strip_tags FTW

    Easiest 70 points you'll make on x10

    Feel free to add my reputation by clicking on the if you found my post helpful to you :P


    If I am not responding to your PMs, that means I am ignoring you. Take a hint.



    09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0


  4. #4
    str3zz is offline x10Hosting Member str3zz is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    5

    Re: PHP remove html/other uncessary tags? - need help

    new to php still confuse my self about it. sorry can't help

  5. #5
    Thewinator is offline x10 Lieutenant Thewinator is an unknown quantity at this point
    Join Date
    Oct 2007
    Location
    [NL]
    Posts
    256

    Re: PHP remove html/other uncessary tags? - need help

    Also make sure not to accept the null byte. ('%00' or '\0')



  6. #6
    savager is offline x10Hosting Member savager is an unknown quantity at this point
    Join Date
    Sep 2007
    Posts
    10

    Re: PHP remove html/other uncessary tags? - need help

    $_POST['message']=strip_tags;
    OR
    $_POST['message']=string_replace('<', '');

  7. #7
    conker87 is offline x10Hosting Member conker87 is an unknown quantity at this point
    Join Date
    Oct 2007
    Location
    UK
    Posts
    65

    Re: PHP remove html/other uncessary tags? - need help

    You add arrays to that:
    Code:
    $_POST['message']=string_replace(array("<",">"), "");

  8. #8
    a-a-a is offline x10Hosting Member a-a-a is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    20

    Re: PHP remove html/other uncessary tags? - need help

    Thank you everyone!
    One more question. Do I add this after the html form? Or before the if that compares the variables? Or somewhere else?

  9. #9
    engel is offline x10Hosting Member engel is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    54

    Re: PHP remove html/other uncessary tags? - need help

    It should be wherever you are evaluating what the user inputted into the form.

+ Reply to Thread

Similar Threads

  1. Unstand PHP?
    By o0slowpaul0o in forum Tutorials
    Replies: 8
    Last Post: 01-07-2008, 09:16 PM
  2. Sigo con problemas con phpbb2
    By reciecho in forum Soporte
    Replies: 7
    Last Post: 10-20-2007, 06:28 PM
  3. "PHP Startup: Invalid Library" - Interesting error
    By javaguy78 in forum Free Hosting
    Replies: 5
    Last Post: 03-27-2007, 02:33 PM
  4. Remove Documentation PHP Script
    By amr1991 in forum Scripts & 3rd Party Apps
    Replies: 5
    Last Post: 12-09-2006, 11:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers