Creating Website Cookies For Return Customers
Session cookies are small pieces of data that a website sends out to user's web browsers. They can be used to store stateful information or to record the user's browsing activity. This is usually used by sites to either ensure security by making a user's account information only visible when they are logged in. I can make the cookies and access expire upon logging out. Alternatively, I can use the browsing activity records to do targeted advertisements or offer targeted discounts to customers.
For this simple cookie I am calling "site_cookie_1" I want to track returning customers. The cookie also has a built in expiry of one day upon which it will in essence self destruct.
Next I wrote in PHP to reflect to the screen whether the user has a cookie or not. Once the cookie is set there is a visual confirmation with the cookie name echoed back to the user. This can also be sent to a text file for logging purposes.
So now when I first visit the cookies.php page I am greeted with a warning that I have not yet had any cookies set on my account.
For this simple cookie I am calling "site_cookie_1" I want to track returning customers. The cookie also has a built in expiry of one day upon which it will in essence self destruct.
Next I wrote in PHP to reflect to the screen whether the user has a cookie or not. Once the cookie is set there is a visual confirmation with the cookie name echoed back to the user. This can also be sent to a text file for logging purposes.
So now when I first visit the cookies.php page I am greeted with a warning that I have not yet had any cookies set on my account.
Now I reload the page and the cookie script runs. Now a cookie is set and the value is reflected to the screen.
And here reviewing the application details I can see that I indeed have a site cookie named site_cookie_1 with the value of return+customer coming from the server which in this case is localhost and it has an expiry date of one day from now.
Return customer cookie is set. |
Comments
Post a Comment