drzb7969753 2011-03-11 04:59
浏览 53
已采纳

html表单提交方法发布和限制访问帖子文件

I have 2 files, index.html and code.php.

In my html page, I have a form which posts to the code.php on submit like this:

<form method="post" action="code.php"> 

What I am trying to do is only make the code.php accessible to the public when the user clicks submit on the html form. The reason why I am trying to get this done is when the user types in sites.com/code.php it displays a page which isnt processed with the form data and it looks bad, so I want to limit the code.php access.

So basically what I want to do is, when the user goes to sites.com/code.php, they would get redirected to index.html but if they go through the form and hit submit, they'll be able to get to the processed code.php.

I thought of different ways to do this and one of the ways was to change the chmod of code.php with some php script. So by default code.php would not be readable but if the user clicks on submit, the chmod for the code.php wpuld be changed to readable hence displaying the page, but then there is no way to redirect the users to index.php when they just visit code.php.

If there is some fancy way of dong this, please let me know! Thanks.

  • 写回答

3条回答 默认 最新

  • douchen7324 2011-03-11 05:08
    关注

    What you can do is to redirect back to the index.html page when the form is not being posted.

    You can do that checking the REQUEST_METHOD variable.

    if($_SERVER['REQUEST_METHOD'] !== 'POST')
    {
      Header('Location: http://www.mysite.com/index.html');
      exit;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答