简体   繁体   English

codeigniter-隐藏网址中的变量

[英]codeigniter - hide variable from url

I want to do something very simple in codeigniter. 我想在codeigniter中做一些非常简单的事情。 I have a view, which contains several person profiles. 我有一个视图,其中包含几个人的个人资料。 Each person profile has contact button and it should go to a contact form which sends an email to the chosen person. 每个人的个人资料都有联系按钮,它应该转到联系表,该表会向选定的人发送电子邮件。 So I have tried something like this: 所以我尝试过这样的事情:

<a href="http://mywebsite.com/ci.php/controller/contact/<?= $email ?>" class="btn btn-default btn-lg btn-block">Contact</a>

And this is OK, but I do not want the email to be visible in the URL. 可以,但是我不希望该电子邮件在URL中可见。 Is this possible ? 这可能吗 ?

If you don't want data to be visible in the URL you should not use GET. 如果您不希望数据在URL中可见,则不应使用GET。 Instead take a look at the POST method. 而是看一下POST方法。 But if the problem is that you don't want to show just the e-mail, maybe you could pass an user id (or other variable that is unique for each user) in the URL, and use it to fetch the e-mail on the contact page. 但是,如果问题是您不想只显示电子邮件,则可以在URL中传递用户ID(或每个用户唯一的其他变量),然后使用它来获取电子邮件在联系页面上。

(Please note that just because the POST data is not immediately visible in the URL field, it is not completely invisible. POST data can be easily displayed in different debugging tools.) (请注意,仅因为POST数据在URL字段中不立即可见,所以它也不是完全不可见的。POST数据可以轻松地在其他调试工具中显示。)

Yes, it is possible. 对的,这是可能的。 Use an array inside your controller: 在控制器内使用数组:

$emails = array(0=>'email1@website.com', 1=>'..', 2=>'');

Your link would be 您的链接是

<a href="http://mywebsite.com/ci.php/controller/contact/<?= $email_index ?>" class="btn btn-default btn-lg btn-block">Contact</a>

And then do something like this: email_to($emails[$email_index]) 然后执行以下操作: email_to($emails[$email_index])

Well, you get the ideea. 好吧,你得到了理想。

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

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