Login Script (HTML/php)

Status
Not open for further replies.

Benden

maging ang maganda mamatay
Jun 4, 2010
2,281
1,480
LIVE DEMO:
Username: guest
password: guest
also to see error just type random username and pass
Hello I made this html login page it only takes 3 pages
login.php
checklogin.php
login_succes.php

First login.php

HTML:
<title> Page Title</title>
<body background="http://img.sharefast.net/1292283393575221346155.jpg">
<form name="form1" method="post" action="checklogin.php">
<div style="position: absolute; z-index: 1; left: 930; top: 250" id="layer1">
<td colspan="3"><strong>Member Login </strong></td>
</div>
<div style="position: absolute; z-index: 1; left: 850; top: 290" id="layer1">
<td width="78">Email</td>
<td width="6">:</td>
<div style="position: absolute; z-index: 1; left: 100; top: 0" id="layer1">
<td width="294"><input name="myusername" type="text" id="myusername"></td>
</div>
</div>
<div style="position: absolute; z-index: 1; left: 850; top: 330" id="layer1">
<td>Password</td>
<td>:</td>
<div style="position: absolute; z-index: 1; left: 100; top: 0" id="layer1">
<td><input name="mypassword" type="text" id="mypassword"></td>
</div>
</div>
<td>&nbsp;</td>
<td>&nbsp;</td>
<div style="position: absolute; z-index: 1; left: 1055; top: 360" id="layer1">
<td><input type="submit" name="Submit" value="Login"></td>
</div>
</form>
<div style="position: absolute; z-index: 1; left: 850; top: 445" id="layer1">
Havent got an account? <a href="http://www.lifeomg.site40.net/Register.php" target="">get one today!</a>
</div>
Please note that it is a one picture background (N) Im not good with css you also have to edit the divs to fit your login page

Second the checklogin.php (this is a php code)
PHP:
<?php 
$host="your host"; // Host name
$username="your username"; // Mysql username
$password="password"; // Mysql password
$db_name="database name"; // Database name
$tbl_name="members"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");
header("location:home.php");
}
else {
echo "Wrong Username or Password";
}
?>
There is an error with this that I didnt bother fixing as the code still works with it it just has an error code popup when your login is incorrect

Finally login_success.php

PHP:
<?
session_start();
if(!session_is_registered(myusername)){
header("location:main_login.php");
}
?>
<html>
<title> Page title </title>
<body>
Just edit this crap to your needs
</body>
</html>
This is your body for when they did login you can rename it yiou'll have to edit the checklogin.php page then\

Also insert a table called members with a username slot and a password slot also a id slot.


Thanks this is my first please some NICE feedback and no saying it sucks :D
 

Kaz

BooYah
Staff member
Nov 16, 2010
3,064
1,025
its not bad for a first, maybe add a simple landing page once somebody has logged in, then on the landing page, maybe add a log out function that will then send them back to the login page. Then just add to it to improve the look/style of it (if thats what you intend)
 

Livar

Now 35% cooler!
Oct 15, 2010
846
86
I myself personally find these scripts easy, but you could've just found it off another site, or googled "PHP Login script".
 

Kryptos

prjRev.com
Jul 21, 2010
2,205
1,252
Good work, I hope you get to know the language more and try to do more advanced things. It can be better, but it is good for a starter.

Also, if there is ONE off-topic post after this posts, get ready for receiving an infraction.

[mod] Thread cleaned [/mod]
 
Status
Not open for further replies.

Users who are viewing this thread

Top