Question
Open database in phpmyadmin: http://localhost/phpmyadmin Create a new database name login in phpmyadmin. Create a new table: users -- -- Table structure for table `users`
- Open database in phpmyadmin: http://localhost/phpmyadmin
- Create a new database name login in phpmyadmin.
- Create a new table: users
-- -- Table structure for table `users` --
CREATE TABLE IF NOT EXISTS `users` ( `user_id` int(11) NOT NULL, `username` varchar(50) NOT NULL, `password` varchar(50) NOT NULL, `name` varchar(50) NOT NULL ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;
-- -- Dumping data for table `users` --
INSERT INTO `users` (`user_id`, `username`, `password`, `name`) VALUES (2, 'admin', 'admin', 'admin'), (3, 'user', 'user', 'user');
-- -- Indexes for dumped tables --
-- -- Indexes for table `users` -- ALTER TABLE `users` ADD PRIMARY KEY (`user_id`);
-- -- AUTO_INCREMENT for dumped tables --
-- -- AUTO_INCREMENT for table `users` -- ALTER TABLE `users` MODIFY `user_id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=4; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; |
- Create localhost connection: dbcon.php
$con = mysqli_connect("localhost","root","","login");
// Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } ?> |
- Create a session file: session.php
//Start session session_start(); //Check whether the session variable SESS_MEMBER_ID is present or not if (!isset($_SESSION['user_id']) || (trim($_SESSION['user_id']) == '')) { header("location: index.php"); exit(); } $session_id=$_SESSION['user_id'];
?> |
- Create a file CSS style: style.css.
Run your files by localhost: http://localhost/project_name/register.php
Create main page: index.php
- Create links page after successful logged to system: home.php
include('dbcon.php'); include('session.php');
$result=mysqli_query($con, "select * from users where user_id='$session_id'")or die('Error In Session'); $row=mysqli_fetch_array($result);
?>
Welcome:
Log out
|
- Create Logout page: logout.php to destroy user sessions.
session_start(); session_destroy(); header('location:index.php'); ?> |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started