help about php.

Status
Not open for further replies.
5 comments
This is the html part of the code for the layout of the login box.
Code:
<html>
<head><title>Login System By NucleA</title></head>
<body>
<form method=GET action="login.php">
Username: <input type="TEXT" name="Username"><br/>
Password: <input type="TEXT" name="Password"><br/>
<input type="Submit" value="Login">
</body></html>

Code:
<?php
session_start();
 
mysql_connect("YOUR MYSQl SERVER", "MYSQL USERNAME", "MYSQL PASSWORD") or die(mysql_error());
mysql_select_db("Mysql Database") or die(mysql_error());
 
$username=$_GET['Username'];
$password=$_GET['Password'];
$ver=0;
 
$result=mysql_query("SELECT * FROM table") or die(mysql_error());
 
while($row = mysql_fetch_array( $result )) {
 
if($username=$row['Username']){
    $ver=$ver+1;
}
else{
echo "Invalid Username!";
}
 
if($password=$row['Password']){
$ver=$ver+1;
}
else{
echo "Invalid Password!";
}
 
if ($ver=2){
echo "Successfull Login!";
$_SESSION['User']=REGISTERED;
}
 
Hey ,
I knw a lil php . and i wana knw how to make a basic login (username and pass )system using sql

Learn a bit more, you'll put yourself at risk from SQL Injections if you make a login system at your level. You should check out & learn these functions before you even think about starting this project:

mysql_real_escape_string
stripslashes

You should also learn about XSS attacks and how to protect your code from them.
 
I'd have to aggree with Loget on this one. The above one posted by NucleA is far from safe. It takes a lot of knowledge to write a secure safe login script.
Instead of writing it from scratch why not download a pre-made script that you just modify. Their are some good ones like http://www.php-login-script.com/ which you just add your own skin to and modify it as you need. Very safe, easy to modify and lots of features.
 
Status
Not open for further replies.
Back
Top