开发者

Using a combination of SESSION Vars and COOKIE Vars in PHP

开发者 https://www.devze.com 2023-04-07 04:46 出处:网络
Heyo, Odd question... is it possible/ ok. To use a combination of SESSION variables and COOKIE variables... in PHP?

Heyo,

Odd question... is it possible/ ok. To use a combination of SESSION variables and COOKIE variables... in PHP?

I know SESSIONS are stored server side and COOKIES client side...

Is 开发者_开发知识库there any chance of interference? What is the best practise?

Christopher


Actually, sessions are a combination between sessions and cookies since the session ID is stored in a cookie client side. You are free to do pretty much what ever you want with both as long as you remember:

  • Cookies are stored on the client computer. A savvy user has absolutely full control of the contents of a cookie, so don't make assumptions about it's content
  • Session variables are stored in memory on your server, so keep in mind the amount of data you hold for each visitor

PHP's documentation on sessions


You can mix them. By default, the session cookie is set to PHPSESSID that contains the unique session identifier used to associate the client to the session data on the server. As long as you don't interfere with this cookie, it is okay.


In terms of interference it is like just any other two arrays in PHP.
There are some specific issues with each you need to know, like at what phase you can assign variables to each of them etc.

0

精彩评论

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

关注公众号