Dynadot โ€” .com Transfer

Simple PHP login Script

SpaceshipSpaceship
Watch

iDeviseFlash

Established Member
Impact
0
Ok, i haev basically copied and pasted an email to someone, cause lots of people seem to want this. here it is:

I dont recomend using this for extremely important info, but it works fine for most things.
Ok, im gonna go through this piece by piece, so bear with me.
Here is your html file:
<HTML>
<HEAD>
<TITLE>index</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
</HEAD>
<BODY LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0>
<form method="POST" action="login.php">
<div align="left"><p>ย </p>
<p> <input type="text" name="user" size="14">Username
</p>
<p> <input type="password" name="pw" size="14">Password
</p>
<p> <input name="submit" type="submit" value="Submit">
</p>
</div></form>
</BODY>
</HTML>
This simply has two input boxes, one for the username, one for the password, and a submit button. The instance names for the boxes are "user" and "pw". These are important. Now, for the PHP script. We will call it login.php, because in the html form, we told the page to go there. We start of by listing the Users and passwords;
<?
$adminuser = "admin";
$testuser = "test";
$adminpass = "admin";
$testpass= "fubar";
This sets the variable adminuser equal to admin, and the same for test. The second lines set the variables adminpass and testpass equal to there values. For each user you get, you will have to go in here and type in a variable for there username and password. This seems tedious, but it really is not. Now for the next part, the real meat of the code, where it checks to see if your username/password combo works.

if ($user == $adminuser&&$pw == $adminpass || $user == $testuser&&$pw == $testpass)
{
print("Welcome to the administration area!");
}
else
{
print("Wrong password");
}
?>
The first line is an IF statement. It mean, if this is true, do this. So, it checks to see of the text entered in the user and password boxes match.

$user == $adminuser&&$pw == $adminpass
this checks if the text is equal to the admin user and pass that you set. the && means and in PHP, so both of those have to be true. the next part:
|| $user == $mehuluser&&$pw == $mehul)
says OR this. the || means OR in php. So it says, if the text entered is equal to this or this, then they are a user. This method is not susceptable to SQL injection, which is a very nice way to hack a login system. ok, this part:
{
print("Welcome to the administration area!");
}
tells the script that if they are a user and there password is OK, then print this line.
this:
else
{
print("Wrong password");
}
?>
says that if the user/pass combo doesnt work, print that line, and then it ends. This is your very basic login script. Now say you want to redirect to another page. That is easy, you simply replace
print("Welcome to the administration area!");
with
header( "Location: http://www.yoursite.com/yourpage.htm" );
This redirects them to that page. Make two pages, one with the content they are allowed to get to if they are a use, and another, that says like sorry, your either screwed up and are an idiot, :P, or you dont have permission to get here.
Here a complete login script with redirection. I havent been able to hack it yet, and I am in the top like 2% at hackthissite.org so, i think its pretty safe.
<?
$adminuser = "admin";
$mehuluser = "mehul";
$adminpass = "admin";
$mehulpass = "fubar";
if ($user == $adminuser&&$pw == $adminpass || $user == $mehuluser&&$pw == $mehulpass)
{
header( "Location: http://www.yoursite.com/secure.html" );
}
else
{
header( "Location: http://www.yoursite.com/incoorect.html" );

}
?>
They both have to be in the same directory, because of the links.
Ok, hope you understand it, contact me if you dont \/ \/ \/ \/
A NP donation would be realy nice, but you dont have to, just something to say thanks i guess.
Josh
 
Last edited:
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
what prevents somebody from just typing in the url "http://www.yoursite.com/secure.html"
without going through the login page?

(this is probably a very stupid question as i have not yet read anything about securing pages)
 
0
•••
lol, question. how are they gonna find out that is the page :) i told you, i tried to hack this, lol.

and just for you, ill add a boolean flag that says if its false, they cant get there :p
 
0
•••
"what prevents somebody from just typing in the url "http://www.yoursite.com/secure.html"
without going through the login page?"



With something like that people could EASILY find there way in.
 
0
•••
really? would you like to say how? and i said that you shouldnt use this for any extremely valuable stuff, so..
 
0
•••
obviously i was using that particular url as an example, i just used the one that ideviseflash used.

as i said i know absolutely nothing about how to secure pages at this point, but i assume there is a way to keep people from accessing pages without loging in. (maybe by only giving access if you are redirected from the login page? assuming you could determine that. maybe this is what he meant with the boolean flag?)
 
0
•••
y no cookies?
 
0
•••
dont need them, lol. I told you all it was simple, but due to popular demanm :p, im working on a secure script, with boolean flags and cookies. Check for it soon!
 
0
•••
Originally posted by iDeviseFlash
really? would you like to say how? and i said that you shouldnt use this for any extremely valuable stuff, so..

Heres a simple one!

If your site is indexed in google then site:yoursite.com :p
 
0
•••
??? what if i shadow the file, what now :)
 
0
•••
hahaha... id keep ALL the comments coming at flash, because before you know it he has developted the most securem login there is.... :)
then we can all try to break in !
 
0
•••
lol, its not the MOST secure, but im making one that you all can try and hack, and im gonna give a generous NP to the person that can. look for it in the contest forums!
 
0
•••
If you were going to use a script like this and have several users etc then a problem with this script is that they could easily pass the details around not realising they have full access to the area.

This type of login should only be used for information you really dont mind people getting hold of and just wish to stop the casual surfer as to be honest thats all it will stop (and even some of them will come across it accidentally)
 
0
•••
umm, ok. I dont know people that give out there usrers and pass's, but you might.
 
0
•••
Yay! Let's all have a hacking contest. You should make it all secure, then have like 4 - 6 weeks to hack it. First person that does it wins a number of NPs based on how hard it was to hack (in the coder's opinion).

That would be pretty cool. Ofcourse, I'd have no chance, I can't hack to save a blind man from walking of a cliff ;)
 
0
•••
i am :) But dude, in 4-6 weeks, i could hack say, whitehouse.gov? lol, no, im talking you got hours. I could be running scans and see if anyone is doing anything they arent meant to :tu: Ok, the first annual WDT/NP Hacking contest starts now. Im gonna make the script then get back to yall!
 
0
•••
Originally posted by iDeviseFlash
umm, ok. I dont know people that give out there usrers and pass's, but you might.

they wouldnt need to because the page they get sent to does not check they are registered just the page that forwards them.

Many people send people URL's to take a look at and dont realise they can give access to sensitive areas.
 
0
•••
ya, but as i have said, what if i shadow the redirect page or put a boolean flag on it?
 
0
•••
CatchedCatched
Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomDB
NameFit
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back