$link = 'http://download.site.com/player/mobile?id=12&body=<help>ok</help>';
echo htmlentities($link); // http://download.site.com/player/mobile?id=12&body=<help>ok</help>
http://download.<a>site</a>.com/player/mobile?id=12&body=<help>ok</help>
برای ایجاد امنیت توی لینکهایی که کاربران وارد می کنن چیکار باید کرد؟خوب حالا اگه کسی بخواد اذیتت کنه میتونه این آدرس رو بنویسه :
بنظرتون این تابع جلوی اینجکشن و xss رو می گیره؟تابع strip_tags فکر می کنم برای این کار کافی باشه
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
GetSQLValueString($value, "text");
برای جلوگیری از اینجکشن کار رو ساده کردم و اول از تابع htmlentities و بعد از تابع mysql_real_escape_string استفاده می کنم. دیگه کاری به نوع متغیر و ... ندارم. این راه بنظرتون مناسب هست یا نه؟جلوی xss رو می گیره ولی injection ها یک راه حل دیگه داره برای injection از تابع زیر استفاده کنید
$sql = sprintf("UPDATE test_table SET field1 = %s WHERE field2 = %s",
GetSQLValueString($_POST['field1'],'text'),
GetSQLValueString($_POST['field2'],'int'));