FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

Slashes in POST and REQUEST query's

 


taytay
I've got a REALLY annoying problem here. I made myself a pretty nice php page so visitors can send me an email. How ever when they Submit their form data to the server, ot automattically phrases each forrm field containing ' or \ with Back slashes... Originally I thought this was from the "addslashes()" I put in my code... But that's not the case. I made a simple test page to try it out:
Code:
<?php
if(isset($_POST['1'])) { $ga=$_POST['1']; } else {
$ga=""; }
?>
<form action="" method="POST">
<input type="text" name="1" value="<? echo $ga; ?>"><br>
<input type="submit">
</form>
<?
//End
?>


Yet even as simple as that an input containing ' or \ adds More slashes to the echo'd $ga. And every time the input is resubmitted the back slashes double.

Why on earth is the happening???!!!

Even using REQUEST rather than POST i get the same results.
Or if I replace $ga with $_POST['1'].

*tear*
Manofgames
Dum Dum DUUUUM

Sorry for the dramatic music Razz
I think your problem is magic quotes.

Here's a solution I got from Secondversion (http://www.secondversion.com):

Quote:

//Clean the Global $_REQUEST $_POST $_GET $_COOKIE super arrays
if (get_magic_quotes_gpc())
{
function stripslashes_deep(&$array)
{
if (is_array($array))
{
foreach ($array AS $key => $val)
{
if (is_string($val))
{
$array["$key"] = stripslashes($val);
}
else if (is_array($val))
{
stripslashes_deep($array["$key"]);
}
}
}
}
stripslashes_deep($_REQUEST);
stripslashes_deep($_POST);
stripslashes_deep($_GET);
stripslashes_deep($_COOKIE);
}
jabapyth
couldnt you just go through and replace \' with ', and \\ with \?
JayBee
Yes, it is problem related with magic_quotes_gpc.
You can test this configuration by function get_magic_quotes_gpc() and if it returns 1, you should strip all slashes from input ($_POST and $_GET) variables by function stripslashes()

Just read more at php.net manual pages
http://php.net/manual/function.stripslashes.php
http://php.net/manual/ref.info.php#ini.magic-quotes-gpc
http://php.net/manual/function.get-magic-quotes-gpc.php
taytay
ah ha!! I've played around a little with stripslashes() and magicquotes... but stripslashes works just fine for the moment. I didn't try stripslashes before because for some strange reason I was under the impression it didn't exist.... I continue to be proven dumber than I think I am Wink
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.