Best PHP shopping cart tutorial with source – PART 1(index,home,logout)

PHP Shopping cart

Shopping cart simulates effective role today’s online ecommerce platforms. Users like you and me are always having need of ecommerce shopping cart more or relevant solutions.
Apparently this never seems easier rather than confusion. Finally get to the point; outcome of this project.

Wondering – how to build & develop PHP shopping cart?
– The query may return thousands of ideas, lets keep the answer right in the processing during building our PHP shopping cart.
Which language you’re gonna use?
– PHP as this is the most declared and easier to understand.
Can I have the source code?
– Most people gonna come here only to grab the source, I encourage you going through step wise instructions then find source related to that part.
Is there anyway to get support?
– In regards of this php shopping cart, yes you can have limited but relevant support.
Where to run the script of php shopping cart?
– This project I mean PHP shopping cart is built using a smartphone. Definitely you can run on your phone or even online server.
What applications are needed to run the cart successfully?
KickWeb Server application which can run localhost and from localhost you’ll be able to run PHP shopping cart.
– Quickedit or similar text editor which can detect text encoding.

OVERVIEW of PHP shopping cart:

User end:
– index.php (Normal user login)
– register.php (User registration)
– /forget/ (Reset password directory)
– order.php (Submit order)
– cart.php (Cart view)
– profile.php (User profile)
– settings.php (Update user details)
– myorders.php (List order submitted by specific user)

Admin end:
– index.php (Administrator login)
– home.php (Admin dashboard)
– adduser.php (Create user)
– alluser.php (View all users)
– addproduct.php (Create products)
– allproduct.php (View all products)
– allorder.php (List of user’s orders)

Enough talking; stepping directly towards PHP shopping cart.
Launch text editor(QuickEditor) and prepare the index page where our PHP shopping cart login functionality, register and password reset page. The pre-startup index page.

First thing first, Simple but not worth avoiding.
Alright we’ve got minimal login form. It’s action="" sets to htmlentities($_SERVER['PHP_SELF'])
Noticeable are: using only PHP_SELF remains insecure. Does harms to any web application whether PHP shopping cart. It’s open and gives easy accessibility which can be exploited directly. As a result executes malicious scripts performed by user end.
Why not facing a reference?
Usually form action looks like

However, users can entertain by writing some script. Then process the php form carrying following script.

The above block executed. An alert pop-up will appear displaying alert message.
Definitely there are more complex than above example. Anyone have the possibility to run any remote javascript. As reaction we might loose data & important assets from our php shopping cart.
Lets process the form avoiding any harmful script.

Apparently, any script processes through the form becomes non-executable by using htmlentities($_SERVER['PHP_SELF']) function.
The malicious script tag then sanitize and outputs as below:

<form action="form-action.php/&quot;&gt;&lt;script&gt;alert('xss')&amp; lt;/script&gt;&lt;foo" method="post" name="test"></form>

Almost every servers got automated protection by sanitizing the process. For furthermore its always recommended to use htmlentities() with PHP_SELF.

index.php [Login page]:
So index page of our PHP shopping cart dont have any header or footer included, lets put some standard doctype header & meta. Prettify the look by adding bootstrap as stylesheet. Wait take a look

dbconnect.php [Database connection]:
We see a dbconnect.php file at the top of the header page. We’ll structure a database connection which will be embedded across all over our PHP shopping cart.
Get the database connection file

users.sql [Creating table]:
To create the database table you can either import the provided sql file or creating the table manually. Here’s the sql file for users data who will register through php shopping cart.

Let me show you step by step guide from setup & run KickWeb Server including localhost! phpmyadmin and importing SQL. So that you’ll be able to try our PHP shopping cart.


You’ll see early message requires to have storage permission in order to setup the kickweb server & requisites in your phone storage.

If you haven’t done yet, then press -proceed- otherwise press -Already did-

go to the -Permission tab-

Toggle on -Storage- option

Now turn on the server button and check a toast message saying > KickWeb server is Running<

press the upper world >button< and go through your localhost:8080

If everything goes that smoothly, you should see the localhost of your server Local directory (/sdcard/htdocs/)

index.php The [login page]:
Finally we can deploy the index page for PHP shopping cart which should look like:

Has a nice ring huh!

register.php [Registration page]:
Now register page comes where users will register to the php shopping cart in order to having successful login to the home page, take a look at the register page:

home.php [Dashboard page]:
Once the user is registered to our PHP shopping cart he/she can now be able to login from the index page.
After we match the user data we will redirect the user to the home.php page. Here is the home page:

Wanna check the frontend of our recent PHP shopping cart such as index, register & home page?

Here’s our final index page where login functionality has been deployed

The register.php page

The home page after logged in

Lets give a logout option to the user. Here’s the logout page:

For now we can expect us to get covered on index.php (login) page, register.php (registration) page, home.php (dashboard) page and logout.php (logout) page. You can surely check the demo & download the source here.

We will continue to evolve our very own PHP shopping cart.
Till then play with your PHP shopping cart & Keep in touch.

Post A Reply