Storing Form Data as a Session Variable

前端 未结 4 1752
小蘑菇
小蘑菇 2020-11-27 03:58

So I was wondering if it would be possible to store data coming in from a form as a session variable.

Heres what I have so far, but I don\'t know what to put for th

4条回答
  •  离开以前
    2020-11-27 04:37

    To use session variables it's necessary to start the session by using the session_start function, this will allowed you to store your data in the global variable $_SESSION in a persistent way.

    so your code will finally looks like this :

    Test Form
    

    to make it easy to use and to avoid forgetting it again, you can create a session_file.php which will be include in all your codes and will start the session for you

    session_start.php

      
    

    and then include it wherever you like :

    Test Form
    

    that's is the more portable and easy way to maintain in the future.

    other remarks

    • if you are using Apache version 2 or more, be carefull instead of

      to open php's tags, use , otherwise your code will not be interpreted

    • variables names in php are case-sensitives instead of write $_session, write $_SESSION in capital letters

    good work !

提交回复
热议问题