I am developing open source portal script, and for security reason I am using addslashes function with magic quotes and trim for inserting the inputs in the database…etc
This is my code:
Code: Select all
<?php
function add_slashes($Str)
{
if (@get_magic_quotes_gpc()){
if ( is_array($Str) ){
foreach ($Str as $k => $v){
$Str[$k] = trim($v);
}
}else{
$Str = trim($Str);
}
}else{
if ( is_array($Str) )
{
foreach ($Str as $k => $v)
{
$Str[$k] = addslashes(trim($v));
}
}
else
{
$Str = addslashes(trim($Str));
}
}
return $Str;
}
?>Example:
First Line
Second Line
The result:
First Line rn Second Line
Or
First Line \r\n Second Line
I fond that the Magic quotes gpc is turned on in my server and the function working fine with me, and for those people who complained from that problem the Magic quotes gpc is turned off
How to write a function that checks if magic quotes is running and then runs addslashes () based on the results?
Kind regards,