Php login with cookie, provide username and password store it in cookie container
This tutorials is assume you have been following up on other tutorials, such as php signup page. You have signup page already, if you don't have any, then I think you need to create one. if you look at the code below this is html form already-made you can copy and paste for our testing. Now, copy the code below or write it manually and save it as index.php and run it to see a nice decorated ligin form.
Login the user and retrieve the protected page
The php script below, copy and paste on top of your html tag, this script should come first before anything else in your application. In this script, this script will open our database, in the table select the appropriate user and compare it with the one typed in the input field, if the two data are equally the same it open protected page for user. If it's not available in our database will open error page and display what went wrong. Now copy the code below and paste on top of your html file and save it as index.php run the page type username and password to login and view user profile.
Browsing the protected page called welcome to our homepage
Now, if every thing goes well we will retrieve a specific users from our database, especially a valid user that has been registered. It will retrieve general information about registered user such as: id, image, fullname, fulladdress, emailaddress, phonenumber, username, password, project, subscription, gender, registered date. Now, copy or write the below code manually and save it as success.php this will retrieve user profile.
'.$_SESSION["fulladdress"].'
'; echo ''.$_SESSION["emailaddress"].'
'; echo ''.$_SESSION["phonenumber"].'
'; echo ''.$_SESSION["username"].'
'; echo ''.$_SESSION["password"].'
'; echo ''.$_SESSION["project"].'
'; echo ''.$_SESSION["subscription"].'
'; echo ''.$_SESSION["gender"].'
'; echo ''.$_SESSION["reg_date"].'
'; echo "Logout";After login attempt failure in our database
While trying to login, if the username and password doesn't exist, we will re-direct the user to invalid page. Remember that we stored whatever details they type in our input field in cookie container. Now, retrieve that username and password telling them that he or she can't login and what they can do to be able to login. Copy and paste below code or write it manually, save it as invalidpage.php
Attention please!
The below details are not valid:
Your username:
Your password:
To be able to login you need to register:
- Provide profile picture
- Provide full name
- Provide full address
- Provide email address
- Provide phone number
- Provide username
- Choose password
- Select project type
- Select gender option
There is no already made account which you can initialize to login. You need to register and obtain new account.
Deleting session container after storing items in it or logout
After using session containers it's a good practice to clear everything in it leaving it empty. In the below script, this script will help logout users that was previously logged in. Now, copy and paste below code or write it manually save the code as logout.php for your testing.
Summary
This script was prepared with all the seriousness in the world, if you are struct anywhere, don't hesitate to ask questions, we are open to answer your question at any time. Thank you for reading this articles.
Comments