Skip to content

ThirteeNov

My personal blog about coding and internet

Menu
  • About me
  • About Zofia Kreasi
  • Cart
  • Checkout
  • Making an airplane game from scratch in Unity
  • My account
  • Privacy Policy
  • Privacy Policy – zkLeaderboard
  • Sample Page
  • Shop
  • Tutorials on Learning JavaScript
  • ZKAccounts – Privacy Policy
Menu

Very Easy and Simple PHP Login and Logout Tutorial

Posted on January 4, 2019August 4, 2020 by Habibie

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>
<html>
	<head>
		<title>PHP Login and Logout</title>
	</head>
	<body>
		<?php
			session_start();
			if(isset($_GET["logout"])){
				session_destroy();
			}
			$username = "habibie";
			$password = "somepassword";
			if(isset($_POST["username"]) && isset($_POST["password"])){
				if($_POST["username"] == $username && $_POST["password"] == $password){
					echo "<p style='color: green;'>Login Success!</p>";
					$_SESSION["user"] = $_POST["username"];
				}else{
					echo "<p style='color: red;'>Login failed!</p>";
				}
			}
			if(isset($_SESSION["user"]) && $_SESSION["user"] == $username){
				?>
				<p>Welcome. You are loged in. Click <a href="?logout">here</a> to logout.</p>
				<?php
			}else{
				?>
				<form method="post">
					<label>Username</label>
					<input name="username" type="text"><br>
					<label>Password</label>
					<input name="password" type="password"></br>
					<input type="submit" value="Login">
				</form>
				<?php
			}
		?>
	</body>
</html>
Post Views: 441
ciihuy2020

Welcome!

  • My YouTube Channel
  • My GitHub Page
  • About me

Categories

  • 3DVista
  • Android
  • Apache
  • C#
  • Cordova
  • Electron & Node JS
  • HTML5, CSS & JavaScript
  • iOS
  • Let's Make Unity Games
  • Misc
  • Photoshop
  • PHP
  • Python
  • Uncategorized
  • Unity
  • WordPress

Recent Posts

  • Hover Reveal script for Unity to show and hide object on mouse hover
  • How to Prevent UI Clicks in Unity from “Bleeding Through” to 3D Objects Behind Them
  • Make objects like wires and cables easily in Unity using Ciihuy Curved Mesh
  • [SOLVED] Can’t Add Custom Domain to Blogger After Losing CNAME Verification
  • iOS App Icon Generator by CiihuyCom
© 2026 ThirteeNov | Powered by Superbs Personal Blog theme