简体   繁体   English

返回字符串$ _GET字符串参数以外的数据的其他方法?

[英]Other ways to return data other than string $_GET string parameters?

So im asking what options do I have other than redirecting GET variables when Im trying to repopulate a form? 所以我问我试图重新填充表单时,除了重定向GET变量外,我还有什么选择?

Im thinking I can create session variable and use that also. 我想我可以创建会话变量,也可以使用它。 Am I correct that these are the ONLY 2 ways? 我是否正确,只有这两种方法?

What I have now is: 我现在所拥有的是:

if ( count($m) > 0 ) {    
// there is an error in fields filled out so we are sending user back to     form.
$_SESSION["myarray"] = $m;
header("location: ./edit.php?datefield=".$datefield."&text=".$entry."&flag=".$flag);    
}

but this reveals my variable to the user. 但这向用户显示了我的变量。 I want to avoid this. 我想避免这种情况。

UPDATE I re-worded my question and the code to be clearer. 更新我重新措辞了我的问题,并使代码更清晰。 I also like found that the solution for me was to use an include('edit-error.php'). 我还喜欢发现对我来说解决方案是使用include('edit-error.php')。 Which is basically the original edit.php with everything stripped out but the code needed to generate the form, and I populated edit-error.php with the needed variables. 这基本上是原始的edit.php,其中删除了所有内容,但是生成该表单所需的代码,然后我用所需的变量填充了edit-error.php。 I never had this in my tool box before so I am grateful to the user who suggested it. 我以前从未在工具箱中使用过此工具,因此我对提出该建议的用户表示感谢。

One way that you can consider for hide information (not totally, but more stronger than GET) of user is create a JSON with your infos and send a POST request to your page. 您可以考虑为用户提供隐藏信息(不是全部,但比GET更强大)的一种方法是使用您的信息创建JSON并将POST请求发送到您的页面。

Personally, I still preferring sessions, but there are other ways. 就个人而言,我仍然更喜欢会议,但还有其他方法。

The solution I used was provided my user pala_ , so thanks pala_ I up voted your comment. 我使用的解决方案是为用户pala_提供的,因此感谢pala_我投票支持您的评论。

I used include('edit-error.php'). 我用了include('edit-error.php')。 Which is basically the original edit.php with everything stripped out but the code needed to generate the form, and I populated edit-error.php's form with the needed variables. 这基本上是原始的edit.php,其中删除了所有内容,但是生成该表单所需的代码,然后用所需的变量填充了edit-error.php的表单。 I never had this in my tool box before so I am grateful to the pala_ who suggested it. 我以前从未在工具箱中添加过此功能,因此我感谢提出该建议的pala_。

This allows me to conduct server side validation and redisplay the form again with user input, so they can resubmit. 这使我可以进行服务器端验证,并通过用户输入再次重新显示该表单,以便他们可以重新提交。 I was using header(Location) with paramaters to submit as GET and I didnt want that. 我正在使用带有参数的标头(Location)提交为GET,但我不希望这样。 Using include() is a perfect solution for me. 对我来说,使用include()是一个完美的解决方案。

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

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