php login scripts

Any problem with PHP can be disscused here
Post Reply
karanmalik
Posts: 3
Joined: Wed Feb 16, 2005 7:20 am

php login scripts

Post by karanmalik »

hi
can anyone refer a good secure php login script please

thanks


kmove
Posts: 11
Joined: Mon Feb 14, 2005 5:17 pm

Post by kmove »

Hello

If you want protect a part of your website, admin section for example, you can use in Cpanel "Password Protect Directories".
Lixas
Posts: 750
Joined: Wed Feb 16, 2005 4:21 pm

Post by Lixas »

This should be in your functions file, for example "f.php"

Code: Select all

function check($u, $p){ 
	$q = mysql_query("select * from user where `nick` = '$u'");
	$n = mysql_num_rows($q);
	$r = mysql_fetch_array($q);
	if ($n == 0) return false;
	else {
	if ($r["password"] == $p)
		return true;
	}
}
This one should be on top of login page

Code: Select all

if (check ($nick, $password) == true){
	$in = 1;
	session_register("nick", "password", "in");
    $username = mysql_fetch_array(mysql_query("SELECT * FROM user where `nick` = '$nick'"));
} else $in = 0;
By cheking "in=1" then that user is logged in, and if in = 0 then user not logged in

Code: Select all

<form method="POST">
				  <input type="hidden" name="login" value="1">
                    <p align="center" class="meniu">
                    <input type="text" name="nick" size="16" style="font-family: Verdana; font-size: 8pt"></p>
                    <p align="center" class="meniu">
                    <input type="password" name="password" size="16" style="font-family: Verdana; font-size: 8pt"></p>
                    <p align="center" class="meniu">
                    <input type="submit" value="Log In" name="B1" style="font-size: 8pt; font-family: Verdana"></p>
                    <p align="center" class="meniu">[b]<span lang="lt">
                    [url=reg.php]Register[/url]</span>[/b]</p>

                  </form>
This is html source for for login, place it wherever u want
Lixas
Posts: 750
Joined: Wed Feb 16, 2005 4:21 pm

Post by Lixas »

if u want not mysql based login, try to use this "f.php"

Code: Select all

function check($u, $p){
$username= "somename";
$password= "somepassword"
   if (($u == $username)&&($p == $password)) return true;
   else {
        return false;
   }
}
Simple, but this is only for one user, all other source is the same like in post before

P.S. do not forget to place includes in your login page:

Code: Select all

include("f.php");
Post Reply