NameSilo

Stripslashes

SpaceshipSpaceship
Watch

SiKing

Registered MemberEstablished Member
Impact
6
Hey, been using addslashes and stripslashes all this time but I've been told this is wrong. Can anyone give me the low-down on magicquotes? Thanks
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
If you want to understand it better, you should readthis ;)
 
0
•••
Simply put magic quotes are the bane of PHP. To make things worse magic quotes settings can vary from one server to another. Please note that since PHP 4.0x magic quotes are disabled by default.
Of course people on a shared server do not have access to the PHP config file so it's best practice to design portable code so you don't depend on server-specific settings.

I use this piece of code in a config file (as an include at the beginning of my scripts) so as to avoid finding unwanted \ in my form requests :gl:
PHP:
if (get_magic_quotes_gpc()) {
	function stripslashes_deep($value) {
		$char_array = array();
		$value = is_array($value) ? array_map('stripslashes_deep', $value) : strtr(stripslashes($value), $char_array);
		return $value;
	}
	$_POST = array_map('stripslashes_deep', $_POST);
	$_GET = array_map('stripslashes_deep', $_GET);
	$_COOKIE = array_map('stripslashes_deep', $_COOKIE);
}
 
0
•••
Thanks for the help guys..and girls
 
0
•••
well I always use this function at the beginning of scripts:

PHP:
function unmagic_quotes()
{
	for($i = 0; $i < func_num_args(); $i++)
	{
		$temp = func_get_arg($i);
		if(is_array($temp))
		{
			foreach($temp as $key => $val)
			{
				if(is_array($GLOBALS[$key]))
				{
					_unmagic_quotes($GLOBALS[$key]);
				}
			}
		}
		else
		{
			stripslashes($GLOBALS[$key]);
		}
	}
}
if(get_magic_quotes_gpc())
{
	unmagic_quotes($_GET $_POST, $_REQUEST, $_COOKIE);
}
if(get_magic_quotes_runtime())
{
	set_magic_quotes_runtime(0);
}

And it works :D
 
0
•••
CatchedCatched

We're social

Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomDB
NameFit
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back