For php you need a web server that hosts with PHP and MySQL. A sample is listed below:
Note: You should get yourself familiar with PHP and MySQL
Create MySQL table:
create table logins (
id int unsigned auto_increment not null primary key,
username varchar(20) not null,
password varchar(20) not null,
session varchar(20) not null
)
Insert your logins into MySQL
First, connect to your database with the user and pass your host provider offers. This script should be its own file like connect.php and included in any page you need a db connection
$db=mysql_connect("localhost","mysqluser","mysqlpass");
mysql_select_db("yourdatabase",$db);
$sql="INSERT INTO logins (username, password) VALUES ('yourusername','yourpassword)";
$res=mysql_query($sql);
Login:
yourphpscript.php
if (isset($_POST['login'])) {
$sql="SELECT * FROM logins WHERE username='$_POST['user']' AND password='$_POST['pass']'";
$res=mysql_query($sql);
$num=mysql_num_rows($res);
if ($num > 0) {
$session=rand(000000,999999);
$sql="UPDATE logins SET session='$session' WHERE username='$_POST['user'] AND password='$_POST['pass']";
header("Location:secretpage.php?session=$session");
exit();
}
else {
echo "That login is invalid. Please try again.";
exit();
}
Validate script on your secret page.
$sql="SELECT * FROM logins WHERE session='$_GET['session']'";
$res=mysql_query($sql);
$num=mysql_num_rows($res);
if (!$num || !$_GET['session']) {
echo "You are not a valid user. Please login.";
exit();
}
2006-07-21 02:29:26
·
answer #1
·
answered by rob 3
·
0⤊
0⤋
By using HTML and JS, the password would be insecure. The user could disable JS, view the source of the page, and get the password. If it is in another file, they could find a way to open up that file and get the password. Also, once they have the page source, they have the whole page. They just have to save that as an html file and open it up.
The best solution would be to read up on some server side languages (php, perl, etc.) That way, they have no way to get to the password info.
2006-07-21 01:21:36
·
answer #2
·
answered by Cheater 2
·
0⤊
0⤋
If you want to make it truely secure, you have to do it on the server side. Many hosting companies allow you to password protect some directories. Other than that you will need to set up a back end technology like PHP or ASP to check passwords entered against a database entry.
2006-07-21 01:42:49
·
answer #3
·
answered by John J 6
·
0⤊
0⤋