开发者

Pass global variables through php form?

How do i save variable with codeigniter through pages on a form, on the first page i receive all the variable开发者_StackOverflow社区s that i need on the form, i want to save those variable to postData, an be able to access them on everypage in my form?


In most cases, the simplest approach would be to leverage Sessions. For example, to assign your "global" var using sessions in php:

session_start();
$_SESSION["var_name"] = $temp_var;

Please note: session_start(); must be included on each page when referencing any session variables.

** Note: If you do go the route of hidden form input fields, all users will be able to view the value of the variable. In addition, you must assign the hidden input fields through out each step of the various pages that deal with the user form.


Note that experienced users can edit hidden fields, ensure to validate data and be carefull with CSRF

You should use Session or Flashdata http://codeigniter.com/user_guide/libraries/sessions.html

CodeIgniter supports "flashdata", or session data that will only be available for the next server request, and are then automatically cleared. These can be very useful, and are typically used for informational or status messages (for example: "record 2 deleted").

Note: Flash variables are prefaced with "flash_" so avoid this prefix in your own session names.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜