dsiftnc99059 2016-11-30 14:44
浏览 116
已采纳

如果URL中有任何html实体,是否会自动解码URL?

The scenario:- I am redirecting the user to the previous page after the successful login. login.php has a form which takes username and password and POSTs to the login_check.php. login_check.php checks for authentication of the user and if passed it redirects the user to the default page unless the user has a choice(i.e: if he visited to some other page,say people's.php and that people's.php finds that he is not logged in and redirects him to login page so that he can get back after successful login). I am also storing the visited URL in a hidden field in the form in login.php :-

echo '<input type="hidden" name="location" value="';
 if(isset($_GET['location']))
 {
  echo htmlspecialchars($_GET['location']);
 }
echo '"/>';

In login_check.php, after authentication check I check whether there is a user choice otherwise redirects him to default page:-

//REDIRECT USER TO PREVIOUS PAGE IF ANY
if(isset($_POST['location']))
{
   header("location:".$_POST['location']);
   exit;
} 

My question:- If I write the URI people's.php in the browser it prompts me to log in accordingly and redirects me after login.If I try something like people&amplsquo;s.php I get page not found message.(As Encoded URL using htmlspecialchars() is stored in the hidden field as shown in the code above). So,where does the decoding of the URL take place and why does it not work the other way(i.e:people&amplsquo;s.php)?

  • 写回答

2条回答 默认 最新

  • douhu7807 2016-11-30 14:58
    关注

    If you write an HTML entity in an HTML document (and not inside an element with intrinsic CDATA, like <script>), then the entity will be decoded as the HTML is parsed and the DOM is generated.

    This is what happens in your <input value=... example.

    When the browser constructs the URL from the inputs in the form when the form is submitted, the entities have already been decoded.


    When you put an HTML entity in an HTTP header (such as location, then it will not be decoded by the browser. HTTP headers are not HTML documents so will not be parsed as HTML.

    In your example, the entity was already decoded by the browser before being sent to the server to populate $_POST.


    When you put an HTML entity in the browser's address bar, then it will not be decoded by the browser. URLs are not HTML documents so will not be parsed as HTML.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥15 绘制多分类任务的roc曲线时只画出了一类的roc,其它的auc显示为nan
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?