Posts

Showing posts from April, 2018

How to Create and Remove Cookies in PHP Web Applications and How Do They Work

Image
First I would explain basics cookies in web applications and how they work. Then, I have listed the PHP code to create, read and remove cookies with brief description of each task. Its comprehensive post, so feel free to not read in one sitting, take breaks but absorb as you read. What are Cookies A cookie is data in the form of key value pair e.g.  city=Lahore, id=90,  that is stored in user's web browser. Cookies are created in web browser on the instuction of web server. Once some cookies are create/stored in web browser (we would shortly see how to create them), when user send new requests to same web application, existing cookies are automatically added in HTTP request by the web browser. So the data stored by web developer in user browsesr (in the form of cookies), automatically reaches back at server in subsequent requests. When web server send instruction to create a new cookie, it also send cookie expiry time to browser (or default time is used, explained later), tha

How to Use Sessions in PHP Web Applications

Image
How does session work in web applications , covers basic concepts of session management. If you are new to web sessions, you should read that post first. This article follows code centric approach i.e. it contains different code samples with brief description. It covers: how to create a session in PHP, how to put some data in session, how to get data from session, how to remove specific data element from session or all of the session data at once. Consider it a reference article of code samples of PHP Sessions. How to Create New Session in PHP The below PHP file i.e. create_session.php creates new session at web server when the page is accessed from browser. session_start() method is used to create a new session. When session is created, a unique session ID is generated, we can read the value of session ID by calling session_id() function. Server send the generated session ID to browser where it is stored as cookie, named PHPSESSID. When user send another request, browser auto

Create a Simple E-Commerce Store - Assignment 2

Image
Create a simple e-commernce store to practice different concepts of web programming we discussed in class e.g. Bootstrap, form handling, files handling, sessions, cookies, database connectivity etc. E-commerce stores are used to sell products. The end product shall have Bootstrap based UI, so feel free to use a free Bootstrap theme. From functional perspective, your assignment shall look something like this:  https://demo.oscommerce.com  (UI shall be better) The store shall have at least following functionalities: Use bootstrap 4 for layout and different page components e.g. forms, panels, cards, etc. It shall allow users to register, login, logout, change password, and edit profile. Use any basic attributes. After admin is login, admin (user type) shall add new products and categories. Let admin to update and delete both entities. Category shall have only name and id. Products shall have title, description, price, in-stock, and category_id fields. Let admin to upload ma