+ Reply to Thread
Results 1 to 6 of 6
Like Tree2Likes
  • 1 Post By misson
  • 1 Post By misson

Thread: Problem with $_POST in PHP

  1. #1
    gdebojyoti.mail96 is offline x10Hosting Member gdebojyoti.mail96 is an unknown quantity at this point
    Join Date
    Mar 2011
    Posts
    57

    Problem with $_POST in PHP

    Hello,

    I faced a problem while trying to use the $_POST command in PHP.

    Whenever I am trying to receive a string which contains any of the characters ', ", \, the output character is accompanied by a \ character.

    Code:
    <?php
    
    $mystring=$_POST["mystring"];
    
    echo $mystring;
    
    ?>
    Input: He's known as Michael "Mickey" Brown. This is a \ character.
    Output: He\'s known as Michael \"Mickey\" Brown. This is a \\ character.

    ---------- Post added at 12:03 PM ---------- Previous post was at 12:00 PM ----------

    Please note that this problem did not arise when I was using the code in my computer's localhost (Wamp); it started when I uploaded the file in my x10hosting's account.

  2. #2
    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: Problem with $_POST in PHP

    http://php.net/manual/en/function.stripslashes.php

    Use stripslashes( $input ) on any input from forms, since the x10 servers add the slashes because magic_quotes_gpc ( http://www.php.net/manual/en/info.co...gic-quotes-gpc ) is set.
    Nothing is always absolutely so.

  3. #3
    Skizzerz's Avatar
    Skizzerz is offline Contributors Skizzerz will become famous soon enough
    Join Date
    Nov 2007
    Location
    Texas
    Posts
    2,153

    Re: Problem with $_POST in PHP

    I'm not sure why this is on in the first place, I'm going to talk with the admins to see if I can get that changed since it's been deprecated for years.

    However, I suggest that you check the current value of magic_quotes_gpc (either via ini_get() or get_magic_quotes_gpc()) before applying stripslashes() because it will be turned off in the future (it is slated to be completely removed from a future PHP version, but it may be disabled before then).
    Ryan Schmidt | Level 2 Support
    █ 888-X10-9668 - ryan[@]x10hosting.com
    x10Hosting - Giving Away Hosting Since 2004
    Premium Hosting | VPS Services

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

    Re: Problem with $_POST in PHP

    It's probably because so many neophyte developers are completely oblivious to SQL injection, and magic quotes provide at least a small measure of protection for X10's servers. IMO, the registration Turing test should be replaced with something about SQL injection, so X10 can be fairly sure the user won't create vulnerabilities on the servers.

    See the various magic quotes threads on X10 for ways of easily undoing magic quotes.

    Debojyoti Ghosh, make sure you understand how SQL injection works, and how to prevent it, which is mostly very simple: parameterize statements so user input is kept out of the statement. It's rather like defining a function, with certain values in the statement made into parameters.

    See also:
    Last edited by misson; 01-07-2012 at 02:16 AM.
    gdebojyoti.mail96 likes this.
    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.

  5. #5
    gdebojyoti.mail96 is offline x10Hosting Member gdebojyoti.mail96 is an unknown quantity at this point
    Join Date
    Mar 2011
    Posts
    57

    Re: Problem with $_POST in PHP

    Sorry for the very late reply.

    Thanks for your advice, everyone.

    By the way, 'stripslashes' solved the issue.

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

    Re: Problem with $_POST in PHP

    Also, note that $_POST isn't a command, it's a variable. In some languages, there isn't much difference between code and data, but PHP isn't quite that way.
    gdebojyoti.mail96 likes this.
    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.

+ Reply to Thread

Similar Threads

  1. Replies: 0
    Last Post: 04-04-2011, 02:21 PM
  2. Replies: 3
    Last Post: 07-08-2010, 01:47 AM
  3. php includes and $_GET and $_POST variables.
    By lambada in forum Scripts & 3rd Party Apps
    Replies: 3
    Last Post: 07-29-2006, 01:35 PM

Tags for this Thread

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