简体   繁体   English

如何在我的Perl CGI程序中链接到上一个网页?

[英]How do I make a link to the previous web page in my Perl CGI program?

I have a grid which has a link to next page and I have a button to navigate back to the grid from the current page. 我有一个具有指向下一页链接的网格,并且有一个按钮可以从当前页面导航回网格。 Until now I was using this method to navigate back ie 到现在为止,我一直使用这种方法向后导航

     <INPUT TYPE="BUTTON" VALUE="Back to Datagrid" onClick="history.go(-1);">

But I faced some issues navigating when I had some other constraints along with that, so I found out something like: 但是当我遇到其他一些限制时,我会遇到一些导航上的问题,因此我发现了一些类似的问题:

    $exit = $ENV{'HTTP_REFERER'};
    <INPUT TYPE="BUTTON" VALUE="Back to Datagrid" onClick="$exit">

But it's not working. 但这不起作用。 I have no idea why, and what's the difference between these two methods? 我不知道为什么,这两种方法有什么区别?

The first method attempts to duplicate the function of the back button. 第一种方法尝试复制后退按钮的功能。

The second method takes whatever the browser claims is the URI of the previous page, put it in the page without sanitizing it, and attempts to run the URI as if it was JavaScript. 第二种方法采用浏览器声称的是上一页URI的任何内容,将其放在页面中而不对其进行清理,然后尝试像运行JavaScript一样运行URI。 This promptly errors because URIs are very rarely valid JavaScript. 这会立即出错,因为URI很少是有效的JavaScript。

The better approach would be to work out the URI you want to go to (presumably based on the data that you used to build the current page with) and create a normal forwards pointing link ( <a href... ) to it … and let the user use the built in back button in their browser if they want to go back. 更好的方法是计算出要转到的URI(大概基于用于构建当前页面的数据),并为其创建一个普通的前向指向链接( <a href... )…和如果用户想返回,则让用户使用浏览器中的内置后退按钮。 This approach: 这种方法:

  • Won't fail if JS isn't available 如果JS不可用,则不会失败
  • Won't fail if their browser doesn't send an optional HTTP header 如果他们的浏览器未发送可选的HTTP标头,则不会失败
  • Won't confuse users by making their browser's history work in unexpected ways 不会使浏览器的历史记录以意外的方式起作用,从而不会使用户感到困惑

I'm not certain, but I suspect there is a risk that someone could craft a URI and put a link on it to your page, including "<script>... in it. A user could then click on that link, get the URI of the page they came from inserted into the page, and introduce you to an XSS attack. (I think this should fail because some of those characters should be URI encoded, but I wouldn't want to risk it — always put in the standard protections against XSS whenever you have data coming from outside your system and back into your page) 我不确定,但是我怀疑有人可能会制作URI并将其上的链接放在您的页面上,包括其中的"<script>... 。然后,用户可以单击该链接,获得将它们来自的页面的URI插入页面,并向您介绍XSS攻击。(我认为这样做应该会失败,因为其中某些字符应使用URI编码,但我不想冒险,请务必放进去每当您有来自系统外部的数据并返回到页面时,针对XSS的标准保护措施)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM