Php htmlspecialchars()或htmlentities()不工作
这是我的密码Php htmlspecialchars()或htmlentities()不工作,php,Php,这是我的密码 $currentPage = SITE_URL.'/'.basename($_SERVER['PHP_SELF'])."?".substr($tail,1); //For example a URL 'http://php.net/docs.php ' $currentPage = htmlspecialchars($currentPage); //$currentPage = htmlentities($currentPage); //I was hoping for a ou
$currentPage = SITE_URL.'/'.basename($_SERVER['PHP_SELF'])."?".substr($tail,1);
//For example a URL 'http://php.net/docs.php
'
$currentPage = htmlspecialchars($currentPage);
//$currentPage = htmlentities($currentPage);
//I was hoping for a output like this 'http%3A%2F%2Fphp.net%2Fdocs.php '
echo $currentPage; //but I get http://php.net/docs.php again
根据手册,我得到与输入完全相同的输出: 此功能与 htmlspecialchars()在所有方面,除了 对于htmlentities(),所有字符 其中包含HTML字符实体 等价物被翻译成这些 实体
因此,在没有看到原始输入的情况下,我只能假设原始输入不包含任何可以翻译的字符。如果得到相同的输出,则没有什么可以转义的
htmlentities()
应将
或&
转换为实体等价物。它只保留其他ASCII字符,如/
或:
。因此,您的URL可能只包含这些内容,但没有&
例如。我想您需要。它将编码http://php.net/docs.php
tohttp%3A%2F%2Fphp.net%2Fdocs.php
如您所愿。使用$\u服务器['SCRIPT\u NAME']而不是$\u服务器['php\u SELF']$_进入/index.PHP/someotherpage.PHP可以欺骗服务器['PHP_SELF']。除此之外,其他人都说了些什么。@igorw他已经在消毒了that@Col.他正在阻止XSS,但basename仍然会给他错误的结果(例如“someotherpage.php”)。@igorw谁?攻击者?公平用户永远不会面对错误的url