Aercor
The Official Gay
- Oct 1, 2011
- 556
- 102
Hello,
I am just starting to learn PHP, and I wanted to make a simple, non-mysql login to guard all my work at school so the noobs wouldn't take my work.
Basically, I have the main login part, I just need two parts added. I can't get my session to work, so I'll stay logged in until the session is destroyed. Secondly, I wanted to make a redirect, if the user is logged in successfully, redirect to blank.php or something.
I will be getting mysql access at school on tuesday, I was wondering how hard it'd be doing that, and having users be able to register and see work I place out for them, not all my stuff though.
Here's a live preview:
I am just starting to learn PHP, and I wanted to make a simple, non-mysql login to guard all my work at school so the noobs wouldn't take my work.
Basically, I have the main login part, I just need two parts added. I can't get my session to work, so I'll stay logged in until the session is destroyed. Secondly, I wanted to make a redirect, if the user is logged in successfully, redirect to blank.php or something.
I will be getting mysql access at school on tuesday, I was wondering how hard it'd be doing that, and having users be able to register and see work I place out for them, not all my stuff though.
Here's a live preview:
You must be registered for see links
- Username: admin
- Password: password
Code:
Index.php:
<?php
session_start();
if($_SESSION['username'] == "username"){
header("Location: login.php");
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Login</title>
<!-- Seo Information -->
<meta name="description" content="Login Page"/>
<meta name="keywords" content="Login, Page"/>
<meta name="author" content="Tyler Schramm"/>
<meta charset="utf-8"/>
<!-- Css Files -->
<link href="css/style.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<form action="login.php" method="post">
Username: <input name="username" type="text"><br></br>
Password: <input name="password" type="password"><br></br>
<input name="submit" value="Login" type="submit">
</form>
<div id="footer">
<p>Copyright 2012 © Tyler Schramm. All rights reserved.</p>
</div>
</body>
</html>
Code:
Login.php:
<?php
session_start();
if (isset($_POST['submit'])){
$_SESSION['username'] = $_POST['username'];
$_SESSION['password'] = $_POST['password'];
if ($_SESSION['username'] == "admin" && $_SESSION['password'] == "password"){
echo "Well done, you have logged in successfully.";
} else {
echo "Sorry, the login information is incorrect.";
}
}
?>