User Dashboard In Php Source Code Free Download
Today we are going to build a registration system that keeps track of which users are admin and which are normal users. The normal users in our application are not allowed to access admin pages. All users (Admins as well as normal users) use the same form to login. After logging in, the normal users are redirected to the index page while the admin users are redirected to the admin pages.
- Php Source Code Free Download
- User Dashboard In Php Source Code Free Download For Pc
- User Dashboard In Php Source Code Free Download Torrent
- Php Website Source Code
Student can free download php project with source code, PHP projects synopsis and Project report with ease of understanding which help the students to give the primary idea before starting of Project. On our PHP tutorial some projects are given. After time by time We Introduce new projects related to PHP. PHP projects free download from PHP. Mar 01, 2018 Java Project Tutorial - Make Login and Register Form Step by Step Using NetBeans And MySQL Database - Duration: 3:43:32. 1BestCsharp blog Recommended for you. Feb 23, 2018 School Management System (SMS) is an advance system build in the PHP. Default user name is admin and password is admin Smart School Management Software http. Online Library Management System project in php free download on phpgurukul. Online Library Management System in php with live demo.
PHP (Pre-Processor Hypertext) is a server-side scripting language, which is considered best for developing the dynamic web pages. At PHPGurukul students can easily download the FREE PHP projects on varied topics according to their requirements. This list of projects in PHP with source code aims to enhance the user’s skills with the dynamic and attractive web application. Student Result Management system in php and mysql. Result Management system in php and mysql. Free php projects Student Result Management system.
So let's start with creating the files, shall we? Navigate to the folder on your machine that is accessible to the server (that is, htdocs if you are using xampp and www if you're using wampp), and create the following files and folders:
Now open up register.php in your favorite text editor and let's start writing some code.
In our blank register.php file, let's add this code:
If we fire up our browser and view this, here's what we get:
That doesn't look cool. Let's do something about it.
Add a link to the css file right under the <title></title> tag in the head section of the register.php file. Like so:
Then open up style.css file and spit out this css code in it:
This css code will be used for styling our entire application.
If we refresh the register.php page on the browser, we get this beauty:
What we want now is for the user to fill the form and press the register button so that the info can be saved in the database. So we move on to the next step.
Php Source Code Free Download
Let's create a database called multi_login. In multi_login database, create a table called users with the following fields:
- id - int(10)
- username - varchar(100)
- email - varchar(100)
- user_type - varchar(100)
- password - varchar(100)
That's all we need for our database.
Let's move over to our register.php file once again and do some modifications.
First we should make sure the form's method attribute is set to post and that the action attribute is set to register.php meaning that when the register button is clicked, the form values are submitted to the same page.
Let's now write the code to receive these values and stores them in the database. But it is my custom to avoid, as much as possible, mixing up php code in html so I'll go ahead and create a functions.php file to put this code inside and then make this code available in the register.php file.
At the very top (first line) of register.php file, add this line of code:
Also, we want that when the user doesn't enter the form values correctly, error messages should be displayed guiding them to do it correctly. In the same register.php file, right after the opening <form> tag, add this code
The display_error() is a simple function we are going to define shortly.
One last thing in the register.php file: Modify the username and email input fields by setting their value attributes to corresponding variables. Like so:
We'll define the $username and $email variables soon..
Now open up the empty functions.php file and add this code in it:
Easy right?
If you observe keenly you can now see the difference between a user and an admin. In the register() function, the user is being saved as admin if the user_type variable was sent in the post request or as user, if no user_type was sent. Since our form doesn't have any field for the user_type, it is obvious that the user we are creating will be saved as user and not admin.
When a user is registered, we get the last inserted id (id of the registered user) and log them in. From the user's id, we are able to get all the other attributes of the user using the getUserById() function. After getting the user, we put them in the session variable as an array called user.
Storing the user in a session variable means that the user is available even if you refresh and navigate to other pages (where session has been started). The user variable in the session doesn't get lost; it can only be lost by unsetting it (this is how we log the user out. Coming soon..).
Now back to our registration form, you notice that when you input values and click the register button, you are redirected to the index.php page. But it's blank. So let's make it look like an index page.
Open up index.php file in your text editor and put the following code in it.
Now if you register a new user, it logs them in and redirects them to an index page that looks like this:
That looks cool.
User Dashboard In Php Source Code Free Download For Pc
Just one tiny problem. If a person types the right url to this index.php page in the browser, they will be able to access this page without even logging in. We don't want that right? Let's fix it.
Unlock password htc desire. Our HTC unlocks by remote code (no software required) are not only FREE, but they are easy and safe. Once it is unlocked, you may use any SIM card in your phone from any network worldwide! As well as the benefit of being able to use your phone with any network, it.
User Dashboard In Php Source Code Free Download Torrent
Let's visit our functions.php file once again and add this function at the bottom of the file:
This function when called, tells you if a user is logged in or not by returning true or false.
Open the index.php file (or any file you want accessible only to logged in users) and paste this code right after the include statement at the top of the file:
If the user is not logged in and tries to access this page, they are automatically redirected to the login page.
To log the user out, let's add this code in the functions.php file:
At this point we can say we are done with user registration.
To do user login is even easier.
Open your login.php file and paste this code in it:
One last thing, add this if statement and this function inside functions.php:
Basically what this does is: if the login button is clicked, the login() function is called which logs the user in. Notice that when the user is logged in, it also does a check: if the user is admin, it redirects them to the admin/home.php page. If however, it is just a normal user, he/she is redirected to the index.php page.
Now let's get to work on the admin site. We are going to be using the files in the admin folder (create_user and home.php). These files are available only to admin users, which means only an admin can create another admin.
Open up create_user.php and paste this code in it:
Besides styling, the main difference between this page and the register page is the option-select field in the create_user.php page that permits the admin to specify the user type. Therefore an admin can create a normal user as well as an admin.
I'll just go ahead and paste the complete code of home.php inside the file. Here it is:
At the top of this file, there is an if statement that checks if the user is admin (using the isAdmin() function). Let's add that function to our functions.php file:
Now you might say, if only an admin can create another admin, then who creates the first admin. Well to create the first admin, you can create a normal user using the registration form, then use any mysql client like phpmyadmin or the mysql command prompt and change the user_type to admin. That way you will be able to log in as admin and create other admins.
As simple as that, we are done with building a system that manages normal users alongside admin users.
Conclusion
I hope this tutorial was helpful to you. I am glad you actually followed it through to the end. Feel free to examine the code, customize it to suit your needs and use it in your projects. If you have any issues or comments or any remarks at all about this tutorial, leave it in the comments below.
Best wishes!