Very Easy and Simple PHP Login and Logout Tutorial

Login and Logout is a must have feature if you are creating a website.

In PHP, I can show you the basic method and mechanism of Login and Logout without any database, at this point.

Watch the video tutorial here:

Here is the source code:

<!DOCTYPE html>
		<title>PHP Login and Logout</title>
			$username = "habibie";
			$password = "somepassword";
			if(isset($_POST["username"]) &amp;&amp; isset($_POST["password"])){
				if($_POST["username"] == $username &amp;&amp; $_POST["password"] == $password){
					echo "<p style='color: green;'>Login Success!</p>";
					$_SESSION["user"] = $_POST["username"];
					echo "<p style='color: red;'>Login failed!</p>";
			if(isset($_SESSION["user"]) &amp;&amp; $_SESSION["user"] == $username){
				<p>Welcome. You are loged in. Click <a href="?logout">here</a> to logout.</p>
				<form method="post">
					<input name="username" type="text"><br>
					<input name="password" type="password"></br>
					<input type="submit" value="Login">

Leave a Reply

Your email address will not be published. Required fields are marked *