如何将PHP会话变量提交到隐藏字段中的表单中? [英] how to submit php session varibles into form in hidden fields?
问题描述
我有一个创建服务器会话变量的脚本。
我需要使用隐藏的表单域将这些变量中的2个插入到一个简单的表单中(在php页面上)。
<?php
session_start();
?>< pre><?php
print_r($ _ SESSION);
?>
我用上面的代码创建了一个简单的php页面。我可以很容易地在页面上看到会话变量,就像你从我们从页面复制的代码的这一部分可以看到的那样:
[login] => andrew8855
[pass] => $ P $ BIsPUTQ / e4mJSlaDsRLA48mB20xxIC1
[email] => andrew@mysiteaddress.com
[name_f] => Andrew
[name_l] =>
[street] =>
[street2] =>
[city] =>
在自定义表单中,我需要从上面获取/打印上面的变量,如下所示:
< input type =hiddenname =login_emailid =login_emailvalue =[email]/ >
< input type =hiddenname =login_userid =login_uservalue =[login]/>
所以当提交表单时,会话中存在的变量将以隐藏形式提交领域。
在搜索了几个小时之后,我发现我可以用session_start()来做到这一点,但是我不清楚如何完成这个。谢谢你的任何建议。
会话以session_start()函数开始。
使用PHP全局变量设置会话变量:$ _SESSION。
如果您没有使用任何自动会话处理框架...如果您使用自己的脚本,那么您必须在使用之前开始会话。您可以尝试
<?php
//开始会话< / p> BR />
session_start();
?>
这是您的脚本的开始位置。之后您可以使用会话变量。
更改您的html模板:
<输入类型=hiddenname =login_emailid =login_emailvalue =<?php echo $ _SESSION ['email'];?> />
< input type =hiddenname =login_userid =login_uservalue =<?php echo $ _SESSION ['login'];?> />
从PHP 5.4开始,无论short_open_tag(php.ini)设置如何,都会启用内联回显短标签。
如果没有启用,请设置
short_open_tag =在php.ini中打开
之后,重新启动Apache服务器,然后您可以使用
<?= $ _ SESSION [ '电子邮件'] GT?;
而不是:
<?php echo $ _SESSION ['email'];?>
您可以尝试 http://www.w3schools.com/php/php_sessions.asp for session.i认为它对你有帮助。
和如何启用PHP短标签?为启用php短标签。
I have a script that creates server session variables.
I need to insert 2 of these variables into a simple form (on a php page) using hidden form fields.
<?php
session_start();
?><pre><?php
print_r($_SESSION);
?>
I created a simple php page with the code above. I can see the session variables easily on the page, as you can see in this part of the code I copied from the page:
[login] => andrew8855
[pass] => $P$BIsPUTQ/e4mJSlaDsRLA48mB20xxIC1
[email] => andrew@mysiteaddress.com
[name_f] => Andrew
[name_l] =>
[street] =>
[street2] =>
[city] =>
In the custom form, I need to get/print the variables from above into the form as so:
<input type="hidden" name="login_email" id="login_email" value="[email]" />
<input type="hidden" name="login_user" id="login_user" value="[login]" />
So when the form is submitted, the variables that exist in the session will be submitted in the hidden form fields.
After searching for hours, I found that I might be able to do this somehow with session_start();....but I'm not clear about how to accomplish this. Thank you for any suggestions.
A session is started with the session_start() function.
Session variables are set with the PHP global variable: $_SESSION.
if you are not using any automatic session handling framework ...if you use your own script then you have to must start session before it use.you can try
<?php
// Start the session<br/>
session_start();
?>
which is set beginning of your script.after that you can use session variables.
Change your html template as such :
<input type="hidden" name="login_email" id="login_email" value="<?php echo $_SESSION['email'];?>" />
<input type="hidden" name="login_user" id="login_user" value="<?php echo $_SESSION['login'];?>" />
Since PHP 5.4 the inline echo short tags are always enabled regardless of the short_open_tag (php.ini) setting.
if it's not enable then please Set
short_open_tag=On in php.ini
after that restart your Apache server then you can use
<?=$_SESSION['email']?>
instead of :
<?php echo $_SESSION['email'];?>
you can try http://www.w3schools.com/php/php_sessions.asp for session.i think it's helpful for you.
and How to enable PHP short tags? for enable php short tags.
这篇关于如何将PHP会话变量提交到隐藏字段中的表单中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!