donglun2024 2016-08-25 11:51
浏览 30

使用php或Jquery / Javascript隐藏/显示表单

I have a problem here which I have solved with two different solutions. I would like to know:

  • Which solution is the most secure?
  • Which solution is more efficient, basically which one requires the least bandwith for user?
  • Which solution in the long run is easiest to maintain?
  • Is there a possibility that any of the solutions might get outdated in the near future? Example if they change how jQuery .hide() works or anything else, whatever.

Here are my solutions:

Solution 1 with jQuery and some php.

jQuery Code:

$(document).ready(function(){

  $.get( "hide_forms_until_logged_in.php", function(  data ) {
    console.log(data.response);
    if(data.response == "false") {
      $("form").hide();
    } else {
      $("form").show();
    }
  }, "json");
});

HTML markup:

<form action="" method="POST" enctype="multipart/form-data">
  <input type="file" name="file" /> <br/>
  <input type="submit" name="submit" value="Upload"/>
</form>

hide_forms_until_logged_in.php:

include 'session.php';
if (isset($_SESSION['login_user'])) {
  echo json_encode(array("response"=>"true"));
} else {
  echo json_encode(array("response"=>"false"));
}

Solution 2 with mostly php:

hide_forms_until_logged_in.php:

include 'session.php';
if (isset($_SESSION['login_user'])) {
  echo "<form action='' method='POST'
  enctype='multipart/form-data'>
   <input type='file' name='file' /> <br/>
   <input type='submit' name='submit' value='Ladda upp'/>
  </form>";
} else {
  echo "Logga in for att ladda upp filer";
}

And inside the page:

  <?php include "hide_forms_until_logged_in.php" ?>

I know I could have made a function and call it inside the include there, for the sake just put the include there.

The form itself before posting anything to database has a check if the user is logged in or not.

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 乘性高斯噪声在深度学习网络中的应用
    • ¥15 运筹学排序问题中的在线排序
    • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
    • ¥30 求一段fortran代码用IVF编译运行的结果
    • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
    • ¥15 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
    • ¥30 python代码,帮调试,帮帮忙吧