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.
Change your html template as such :
Note that if you have
short_open_tags
enabled you can do :instead of :
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
which is set beginning of your script.after that you can use session variables.
Change your html template as such :
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
instead of :
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.
Maybe there's something wrong with the "" and backslashes, but the idea is that you have to put as value $_SESSION['mail'] (or login)