I'm learning one of the most important concept of Cookies in PHP in detail.
While studying Cookies I come to know that "The value of the cookie is automatically URLencoded when sending the cookie, and automatically decoded when received (to prevent URLencoding, use setrawcookie() instead)."
The above statement has created so many doubts in my mind which are as follows :
- What does actually happen practically by means of "The value of the cookie is automatically URLencoded when sending the cookie, and automatically decoded when received" ?
- Why there is a need of another function like setrawcookie() when there is already a function setcookie() available for setting the cookie values?
- Is the process of URL encoding and URL decoding unsafe/harmful/ hazardous/slow/anything else so that it should be avoided?
- What are the benefits/drawbacks of using
setrawcookie()oversetcookie()? - Which one is safe/better/secure/reliable/etc.
setcookie()orsetrawcookie()? - Can't the cookies be set like other variables like
$_COOKIE['cookie_variable'] = 'some_value'instead of usingsetcookie()orsetrawcookie()?
If someone could clear all of my above mentioned doubts with perfect, suitable and easy to understand code examples along with the step-by-step crispy, lucid, easy to grasp explanation it would be of great great help to me.
Thanks.