【问题标题】:How to hide query params when redirecting from php从php重定向时如何隐藏查询参数
【发布时间】:2018-01-23 17:08:54
【问题描述】:

我有一个 index.php 页面,它执行 POST 请求。在发布请求之后,我创建了一个查询字符串

PHP 代码 sn-p : - index.php

// example url : /some-route?&email=test@abc.com&first_name=test
 $url: "/some-route?&email=".trim($_POST["email"])."&first_name=" . 
 trim($_POST["firstName"]);
 header('Location: '.$url);

这是指向 Angular js 路由文件

Angular js -> stateProviderfile -> states.js

     $stateProvider
   .state("some-route", {
     url: '/some-route?isSomeApp',
     templateUrl : 'app/components/application/some-
                   information/someView.html',
     controller : 'someCtrl',
     params: { isSomeApp: null},
     data: { public: true }
});

现在我想检索 Query 参数中的值并将其存储在 $scope 变量中,以便我可以自动填充 someView.html 中的文本字段 我在 someCtrl.js 中使用的代码是:

enter code here
$scope.parse = function(){
    if ($scope.params["first_name"] != undefined) {
      $scope.firstname = $scope.params["first_name"];
     }


   if ($scope.params["email"] != undefined) {
      $scope.email = $scope.params["email"];
     }
}

// call the above function in init() in someCtrl.js
$scope.init = function(){
    $scope.params = $location.search();
  if (Object.keys($scope.params).length > 0) {
     $scope.parseParams();
  }
}

我的问题是:如何在 url 中隐藏 first_name 和 email,以便最终用户看不到它,但以某种方式拥有它,以便我可以访问它 someCtrl.js

我希望用户看到:/some-route

我的代码看到:示例网址:/some-route? &email=test@abc.com&first_name=test

我希望实际网址具有隐藏参数 email 和 first_name - 所以用户看不到这些信息并且 - 我可以从我的代码中访问它

我怎样才能做到这一点?

【问题讨论】:

  • 您不能在 GET 调用中隐藏 URL 参数。您需要为此使用 POST 调用。
  • 在这种情况下如何添加 post call?

标签: javascript php angularjs url uri


【解决方案1】:

如果您只使用两个参数(姓名和电子邮件)进行 POST 调用,并且您想隐藏参数,请使用 HTML 页面而不是带有表单的 PHP 文件,当用户提交时,进行 POST使用 $http 服务在您的 AngularJS 控制器中请求。

继续摇摆!

【讨论】:

    猜你喜欢
    • 2021-02-10
    • 2014-04-06
    • 2013-10-13
    • 1970-01-01
    • 1970-01-01
    • 2016-03-31
    • 1970-01-01
    • 2021-12-11
    • 1970-01-01
    相关资源
    最近更新 更多