faqts : Computers : Programming : Languages : PHP : Common Problems : Forms and User Input : Cookies

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

5 of 9 people (56%) answered Yes
Recently 2 of 6 people (33%) answered Yes

Entry

I can save info from forms in cookies, but how do I save variables generated throughout the code?

Mar 2nd, 2000 13:34
Matt Gregory, Marcus Soares, George Federuik, Onno Benschop,


I can save info from forms in cookies, but how do I save variables
generated throughout the
     code?  versions - edit
Unreleased Questions 
  It is not a really good option save important informations on
cookies.A good things to put into cookie is session_id, minor
configuration variables and stuffs like this. If you use session you can
use you database server to save important information based on
session_id(php4 does this for you , php3 you must implement). 
  You never can trust an information provided by a cookie. Some malicius
user can change it informations and send it back to you making something
wrong on your system. But even if you want to put important information
you can do it by using : (or other separator) to identify each field.
Once again, it is not a good option.
$Cookie = "username=marcus:password=hehehe:creditcardnumber=xxxxx"
or even, 
$Cookie = "marcus:hehehehe:xxxx"
or even better , crypto this information
$Cookie = your_crypt_routine("marcus:heheheh:xxxx")
setcookie(your_cookie_name, $Cookie, ..... );
The only other ways to save variables between scripts is to save them 
to files or to databases.