Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 8 of 8
  1. #1
    Member
    Join Date
    May 2003
    Posts
    6

    Unhappy PHP Problem - What's happening?

    Hi guys,

    I've setup a test form to show what I'm talking about

    => http://ausgamingnetwork.com/testf.php

    Type in the field anything with quotes i.e

    "test"

    -> My question is;

    Why is it removing the content and not putting a \ in like is echoed from the print_r statement? The html code is causing this issue because " " is breaking the input tags. Shouldn't this be getting excluded?

    Any help please?

    The code is:

    PHP Code:
    <?php
    $sent 
    $_POST["submit"];
    $chkAccept $_POST["chkAccept"];
    $name $_POST['name'];

    if(
    $sent){ if($chkAccept) { print_r($_POST); }}
    ?>
    <form method="POST" action="testf.php">
    Name Field: <input type="text" id="name" name="name" size="39" value="<?php echo $name;?>"> <br /> <br />
    Show Print_R Stack: <input type="checkbox" id="chkAccept" name="chkAccept" value="1" checked> <br /> <br />
    <input type="submit" value="Submit" name="submit">
    <input type="reset" value="Reset" name="reset"></p> <br />
    <?php echo $name?>
    </form>
    Also PHP INFO dump: http://ausgamingnetwork.com/info.php

    Thanks guys,
    Last edited by mm6_James; 07-18-2008 at 07:49 AM.

  2. #2
    Member
    Join Date
    Jul 2008
    Posts
    63

    Default

    1) You are not sanitizing your user input at all.
    2) You have magic_quotes_gpc on. While this protects against some forms of failing to sanitize your user input, it also leads to poor programming practices, such as not sanitizing your user input.
    3) You are not sanitizing your user input at all.

    If you look at the resultant HTML source, you will see exactly what the problem is.

    However, before writing any more php code, I strongly suggest you read all of http://www.php.net/manual/en/security.php

  3. #3
    Member
    Join Date
    May 2003
    Posts
    6

    Default

    Hi,

    It's a basic example normally I would addslashes() and stripslashes() but on my previous setup this was never an issue - I'm trying to workout as to why its happening?

    Even when I add slashes is still occurs? Could you perhaps show me some sample code that resolves this issue?

    Thanks

  4. #4
    Member
    Join Date
    May 2003
    Posts
    6

    Default

    Anybody know ?

  5. #5
    ckh
    ckh is online now
    Member
    Join Date
    Dec 2003
    Posts
    333

    Default

    Are you using stripslashes in the file? If not, add it and the problem will go away.

    If you look at the source you will see:

    Code:
    Name Field: <input type="text" id="name" name="name" size="39" value="\"test\"">
    It's only filling in the box with the \ as that is what is surrounded by the quotes and ignoring what is everything after the second quote.

  6. #6
    Member
    Join Date
    May 2003
    Posts
    6

    Default

    I've done that and it does this now:-


    PHP Code:
    Name Field: <input type="text" id="name" name="name" size="39" value=""test""> <br /> <br /> 
    Should I be stripping the quotes? Shouldn't the quotes turn into &quot; so that this is resolved?

    Please advise - thanks

  7. #7
    Member
    Join Date
    May 2003
    Posts
    6

    Default

    Okay I've written up this to deal with < > and ".

    PHP Code:
    <?php
    function smart_quotes($text) {
    $text addslashes($text);
    $text str_replace("\"","&quot;",$text);
    $text str_replace("<","&lt;",$text);
    $text str_replace(">","&gt;",$text);
    $text stripslashes($text);
    return 
    $text;
    }
    ?>
    I will use mysql_escape_string etc for MySQL queries, but is there anything eles I have to consider for form data other than that for injection? Or does that cover it.

    Thanks

  8. #8
    cPanel Development cpanelkenneth's Avatar
    Join Date
    Apr 2006
    Posts
    3,788
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    Quote Originally Posted by mm6_James View Post
    Okay I've written up this to deal with < > and ".

    PHP Code:
    <?php
    function smart_quotes($text) {
    $text addslashes($text);
    $text str_replace("\"","&quot;",$text);
    $text str_replace("<","&lt;",$text);
    $text str_replace(">","&gt;",$text);
    $text stripslashes($text);
    return 
    $text;
    }
    ?>
    I will use mysql_escape_string etc for MySQL queries, but is there anything eles I have to consider for form data other than that for injection? Or does that cover it.

    Thanks
    You should use mysql_real_escape_string()

Similar Threads & Tags
Similar threads

  1. Callbacks still happening
    By cws_support in forum cPanel and WHM Discussions
    Replies: 2
    Last Post: 04-05-2007, 03:29 PM
  2. Weird problem happening with CC Fields
    By Un Area in forum cPanel and WHM Discussions
    Replies: 0
    Last Post: 02-24-2007, 01:50 PM
  3. why is this still happening?
    By HD-Sam in forum cPanel and WHM Discussions
    Replies: 20
    Last Post: 11-23-2004, 09:52 PM
  4. Whtas happening?
    By fucha in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 03-01-2004, 04:14 PM
  5. What is happening to WHM ?????
    By bert in forum cPanel and WHM Discussions
    Replies: 15
    Last Post: 01-20-2003, 07:31 PM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube