Post: Simple PHP Login [P#1]
10-05-2011, 03:21 PM #1
MeowDev
Power to the Premium
(adsbygoogle = window.adsbygoogle || []).push({}); Introduction:
This is part #1 of a series of tutorials I'm going to go over to do with Content Management. In part, I am going to explain the basics of a flat file login page coded in PHP. Unfortunately Screensnapr won't work on my PC so I won't be adding any images.

Step 1
You will need to start off by telling the code what username and password you would like to choose, by using <?php $username = "Telepot"; ?>, etc.
    <?php 

$username = "Telepot";
$password = "password123";

if ($_POST['txtUsername'] != $username || $_POST['txtPassword'] != $password) {

?>

That has basically told the PHP your username and password, this should be put into the first line of a blank document.

Step 2
You will want to put this code below the code posted above, this will be your login page. Continue as you would when coding a normal HTML webpage
    <head>
<title>Sample Login Page</title>
</head>
<body>
</body>

Inbetween them two <body> </body> tags we're going to put the following login form.
    
<form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<p><label for="txtUsername">Username:</label> <br>
<input type="text" title="Enter your Username" name="txtUsername" /><br>

<label for="txtpassword">Password:</label><br>
<input type="password" title="Enter your password" name="txtPassword" /><br>

<input type="submit" name="Submit" value="Login" /></p>
</form>


Step 3
Under the </body> code copy the following simple code:
    <?php 

}
else {

?>

Under that, you can start again with:
    
<head>
<title>Sample Login Page: You are logged in!</title>
</head>
<body>
Welcome to the admin control panel!
</body>

That is the page you're going to see when you've logged in, remember, this is all still in the same page. You can put what ever you want between the <body> </body> tags for your logged in user to see.

You're not done yet! Step 4
Copy the following code after you've done the above step.
    
<?php

}

?>


That's it! You're done! You can customize this login however you would like, for example, I have added a little css and some javascript to my flat file login. Here is one I made earlier!
    
<?php

$username = "Telepot";
$password = "Password13231";

if ($_POST['txtUsername'] != $username || $_POST['txtPassword'] != $password) {

?>
<head>
<title>Ali3n Network - Staff Login</title>
<style type="text/css">
body{background-color:#000;color:#fff;font-family:Arial,Verdana,sans-serif;font-size:62.5%;margin:15% 5% 0 5%;text-align: center;}
a,a:visited,a:active{color:#0080ff;text-decoration:underline;}
a:hover{text-decoration:none;}
input[type=text]{border:1px solid #ccc;color:#ccc;font-size:1em;padding:4px 6px 4px 6px;}
input[type=password]{border:1px solid #ccc;color:#ccc;font-size:1em;padding:4px 6px 4px 6px;}
a.adlink{color: orange;}
#container{clear:both;font-size:3em;margin:auto;}
#name{width:500px;}
</style>
<script type="text/javascript">
function clearboxInput(e) {
if (e.cleared) { return; }
e.cleared = true;
e.value = '';
e.style.color = '#000';
}
</script>
</head>
<body>
<form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<p><label for="txtUsername">Username:</label> <br>
<input type="text" title="Enter your Username" id="name" value="Username" name="txtUsername" onclick="clearboxInput(this);" /><br>

<label for="txtpassword">Password:</label><br>
<input type="password" title="Enter your password" id="name" value="Password" name="txtPassword" onclick="clearboxInput(this);" /><br>

<input type="submit" name="Submit" value="Login" /></p>
</form>
</body>
<?php

}
else {

?>

<p>Welcome to Ali3n. Your objectives will soon be listed here.</p>

<?php

}

?>

If you need any help, feel free to email me at [email][email protected][/email] !
(adsbygoogle = window.adsbygoogle || []).push({});
10-05-2011, 04:40 PM #2
Default Avatar
Jeff
Guest
First comment!
10-05-2011, 04:42 PM #3
MeowDev
Power to the Premium
Originally posted by Jeff View Post
First comment!
<3
Your message was too short
10-06-2011, 04:01 AM #4
JakeM
ZOMG HaXz!
Shouldn't you start a session?
10-06-2011, 04:57 AM #5
Epic?
Awe-Inspiring
Originally posted by JakeM View Post
Shouldn't you start a session?


This clearly isn't a very complex tutorial, I mean, the password is being stored as plain text in the actual PHP file. I think that's all going to come about in future tutorials.

---------- Post added at 09:57 PM ---------- Previous post was at 09:56 PM ----------

Originally posted by JakeM View Post
Shouldn't you start a session?


This clearly isn't a very complex tutorial, I mean, the password is being stored as plain text in the actual PHP file. I think that's all going to come about in future tutorials.
10-06-2011, 05:00 AM #6
JakeM
ZOMG HaXz!
Originally posted by Epic
This clearly isn't a very complex tutorial, I mean, the password is being stored as plain text in the actual PHP file. I think that's all going to come about in future tutorials.


stare yea...
10-06-2011, 03:34 PM #7
MeowDev
Power to the Premium
Yeah this is just the basics of php Smile
10-06-2011, 07:24 PM #8
tylerallmighty
Human After All
Originally posted by Telepot View Post
Yeah this is just the basics of php Smile


I could hack this in 5 seconds. Enzo Like a BAU5

The following user thanked tylerallmighty for this useful post:

Nero.
10-06-2011, 10:41 PM #9
MeowDev
Power to the Premium
Originally posted by bananaman
I could hack this in 5 seconds. Enzo Like a BAU5
Tell us all how you would do it Smile
10-06-2011, 11:35 PM #10
Cory
User needs a dick
Originally posted by Telepot View Post
Tell us all how you would do it Smile


You should make your usertitle smaller, I can't even read your last post.

The following user thanked Cory for this useful post:

Epic?

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo