+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 19

Thread: php and quotation marks

  1. #1
    castaban is offline x10Hosting Member castaban is an unknown quantity at this point
    Join Date
    Aug 2009
    Posts
    9

    php and quotation marks

    Sorry guys, I program very little with php, I just moved my php script here from a different site. I collect user comments in that script and whenever a user types a " or ' it is escaped like \" or \'. It was not happening in my other site. How can I stop this?. Part of my script:
    $filename = 'guest1.html';
    $somecontent = $_POST['Comment'];

    $somecontent will contain \'s..

  2. #2
    xadrieth is offline x10Hosting Member xadrieth is an unknown quantity at this point
    Join Date
    Apr 2009
    Posts
    62

    Re: php and quotation marks

    use:

    stripslashes();

    there is also "addslashes();" if you need to do the oposite.

  3. #3
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: php and quotation marks

    Free hosting here has what is call ' magic quotes ' enabled. Many places have it disabled.

    So input from forms have slashes added.

    As mentioned, if $input contains your input,

    $input = stripslashes( $input ) ;

    should get it back to what the user put in.
    Last edited by descalzo; 10-13-2009 at 03:11 PM.
    Nothing is always absolutely so.

  4. #4
    marshian's Avatar
    marshian is offline x10 Elder marshian is an unknown quantity at this point
    Join Date
    Jan 2008
    Location
    Belgium
    Posts
    526

    Re: php and quotation marks

    Make sure that you check the input if you wish to do such a thing! htmlentities and strip_slashes are very useful!
    Pay attention to code injections.

  5. #5
    xav0989's Avatar
    xav0989 is offline Community Public Relation xav0989 is just really nice
    Join Date
    Jul 2008
    Location
    ifk
    Posts
    4,438

    Re: php and quotation marks

    If you plan in saving the data in SQL, use functions such as mysql_escape_string() & family to protect your application.
    Xavier L | Community Public Relations Manager (Free Hosting Support)
    █ Yes, my position is too cool to even exist!
    How am I helping? Rate this post by clicking the icon below! (this is even better than "liking" a post)
    Terms of Service | Acceptable Use Policy | x10Hosting Wiki

  6. #6
    castaban is offline x10Hosting Member castaban is an unknown quantity at this point
    Join Date
    Aug 2009
    Posts
    9

    Re: php and quotation marks

    Thanks guys, very helpful...
    Output is written to a flatfile, so I don't worry about SQLinjection

  7. #7
    xav0989's Avatar
    xav0989 is offline Community Public Relation xav0989 is just really nice
    Join Date
    Jul 2008
    Location
    ifk
    Posts
    4,438

    Re: php and quotation marks

    Just keep it in mind if you ever plan to move to a database!
    Xavier L | Community Public Relations Manager (Free Hosting Support)
    █ Yes, my position is too cool to even exist!
    How am I helping? Rate this post by clicking the icon below! (this is even better than "liking" a post)
    Terms of Service | Acceptable Use Policy | x10Hosting Wiki

  8. #8
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: php and quotation marks

    If content from the flat file is ever going to be displayed in an application that parses HTML, you'll need something like the filter functions to prevent HTML injection/XSS.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  9. #9
    fretwizz is offline x10Hosting Member fretwizz is an unknown quantity at this point
    Join Date
    Jun 2008
    Posts
    57

    Re: php and quotation marks

    Quote Originally Posted by misson View Post
    If content from the flat file is ever going to be displayed in an application that parses HTML, you'll need something like the filter functions to prevent HTML injection/XSS.
    HTML injection?

  10. #10
    castaban is offline x10Hosting Member castaban is an unknown quantity at this point
    Join Date
    Aug 2009
    Posts
    9

    Re: php and quotation marks

    Now you are worrying me... Flatfile is formatted to be displayed in the browser of course. Format is like this:
    <ul><li>
    <B>Comment: </B> User comment entered here via textarea <BR>
    </ul>

    Are you saying somebody can infect my page using the textarea? If so help appreciated how to prevent that...

+ Reply to Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. php error
    By htmlcent in forum Scripts & 3rd Party Apps
    Replies: 0
    Last Post: 09-09-2005, 06:24 PM

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