FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Login Scripts





mhaitana
Hello does anyone have any scripts to create login accounts on websites?
dandelion
I would recommend you to use the PEAR::Auth package. It isn't a ready script, but you need only a few line to create an authentication system with this package.
sonam
I have this script, but I dont now is it working. I am not using it.

Code:
<?php
if ( (! isset ($PHP_AUTH_USER)) || (! isset ($PHP_AUTH_PW)) ||
($PHP_AUTH_USER != 'home') || ($PHP_AUTH_PW != 'home') ) {
header('WWW-Authenticate: Basic realm="Secret Family Recipes"');
header('HTTP/1.0 401 Unauthorized');
print "You are attempting to enter a restricted area. Authorization is
required.";
exit;}

?>


Sonam
mathiaus
I'd recommend looking through sites such as phpfreaks and hotscripts for something that suits your purposes.
If you know php though make your own. It's better! Smile
gmcclure
Access levels can be used to allow some users access to more pages than others.
To protect a page include the following on top of the page:
Code:

<?php
   include "auth.inc.php";
   verifyAccess(0);
?>

This bit of code includes the authorization scripts and then checks if the user
accessing the page has logged in before and if the users access level is right.
Access is granted to all users of the access level used in the call to
verifyAccess(level) or of a lower level.
e.g. verifyAccess(10) allows access to all users of level 10 and below.
If the user isn't logged in then a login form is shown.
A sample login is provided, but you can customize it by editing the file
auth_login.inc.html.

NOTE: The administrator script is only accessible of users of level 0, so if you add
new users to this level they all will be able to administer the users.

The default login for the administrator is:
username : admin
password : admin

You should change this password as soon as possible using the admin.php script.



users.inc.php
Code:


<?php die("Access restricted"); ?>
admin:f6fdffe48c908deb0f4c3bd36c032e72:0


auth_login.inc.html

Code:

<html>
<body>
<font face="Arial" size=4><b>Sample Login Form</b></font><br><br>

<table width=400 border=1>
<form action="auth_login.php" method=post>
<tr><td bgcolor=black><font face="Arial" color=white size=2><b>Login<b></font></td></tr>
<tr><td><font face="Arial" color=black size=2>Name <input name="username" value="" size=10> Password <input name="userpass" type=password value="" size=10></font></td></tr>
<tr><td><font face="Arial" color=black size=2><input name=submit type=submit value="Login"> <input type=reset value="Clear"></font></td></tr>
</form>
</table>
</body>
</html>


auth_logout.php
Code:

<?php
   setcookie("AUTHORIZER");
   header("Location: $HTTP_REFERER");
?>


auth.inc.php

Code:

<?php
   function authUser($name, $pass) {
      $userlist = file("users.inc.php");
      $done  = false;
      $auth  = false;
      $found = false;
      $i = 1;
      while (!$done && !$found) {
         list($n,$p,$a) = explode(':',$userlist[$i]);
         $found = ($n==$name);
         $auth  = $found && ($p == md5($name.$pass));
         $done  = $auth || ($i>=count($userlist));
         $i++;
      }
      return $auth;
   }

   function verifyAccess($minlevel) {
      global $HTTP_COOKIE_VARS;
      $userlist = file("users.inc.php");
      $done  = false;
      $auth  = false;
      $found = false;
      $i = 1;
      list($name,$pass)  = explode(':',$HTTP_COOKIE_VARS["AUTHORIZER"]);
      while (!$done) {
         list($n,$p,$a) = explode(':',$userlist[$i]);
         $found = ($name == $n) && ($n!="");
         $auth  = $found && ($pass == $p) && ($a<=$minlevel);
         $done  = $found || ($i>=count($userlist));
         $i++;
      }
      if (!$auth) {
         readfile("auth_login.inc.html");
         die("");
      }
   }
?>


auth_login.php
Code:

<?php
   include "auth.inc.php";
   if ( authUser($username,$userpass) ) {
      $exp  = gmdate ("M d Y H:i:s", time()-3600);
      setcookie("AUTHORIZER",$username.":".md5($username.$userpass),$exp." GMT");
   }
   header("Location: $HTTP_REFERER");
?>


admin_edituser.php

Code:

<?php
   include "auth.inc.php";
   verifyAccess(0);
?>
<html>
<head>
<title>Edit User <?php echo $name; ?></title>
<style>
   TD.HEAD   { font-family : Arial; font-weight: bold; font-size: 9pt; color: white; background: black; }
   TD.ROW   { font-family : Arial; font-weight: normal; font-size: 9pt; color: black; background: white; }
   TD.FOOT   { font-family : Arial; font-weight: normal; font-size: 9pt; color: black; background: #DDDDDD; text-align:center}
</style>
</head>
<body>
<font face="Arial" size=2>
<?php
   if (!isset($submit)) {
?>

<table border=1 width="95%">
<tr><td colspan=2 class="HEAD"><b>Edit user <i><? echo $name; ?></i></b></td></tr>
<form>
<tr><td class="ROW">New Password </td><td class="ROW"> <input name="pass" size=10></td></tr>
<tr><td class="ROW">Access Level </td><td class="ROW"> <input name="level" size=10 value></td></tr>
<tr><td colspan=2 class="FOOT"><input type=submit name="submit" value=" Set "></td></tr>
<input type=hidden name="name" value="<? echo $name; ?>">
</form>
</table>
<?php
   } else {
      $userlist = file("users.inc.php");
      $done  = false;
      $auth  = false;
      $found = false;
      $i = 0;
      while ((!$found) && ($i<count($userlist))) {
         $i++;
         list($n,$p,$a) = explode(':',$userlist[$i]);
         $found = ($n==$name);
      }
      if ($pass!="") $p = md5($n.$pass);
      if ($level!="") $a = $level;

      $userlist[$i] = implode(':',array($n,$p,$a));
      $fd = fopen("users.inc.php","w");
      fputs($fd,"<?php die(\"Access restricted\"); ?>\n");
      for ($i=1; $i<count($userlist); $i++) {
         fputs($fd,chop($userlist[$i])."\n");
      }
      fclose($fd);
      echo "<center><b>changes made...</b><br><br><a href=\"javascript: window.opener.document.location.reload(); window.close();\">close</a></center>";
   }
?>
</font>
</body>
</html>   


admin_deluser.php

Code:

<?php
   include "auth.inc.php";
   verifyAccess(0);

   if (isset($name)) {
      $userlist = file("users.inc.php");

      $fd = fopen("users.inc.php","w");

      fputs($fd, "<?php die(\"Access Restricted\"); ?>\n");

      for ($i=1; $i<count($userlist); $i++) {
         list($n,$p,$a) = explode(':',$userlist[$i]);
         if ($n!=$name) {
            fputs($fd,$userlist[$i]);
         }
      }
      fclose($fd);
   }
   header("Location: $HTTP_REFERER");   
?>


admin_delchecked.php

Code:

<?php
   include "auth.inc.php";
   verifyAccess(0);

   if (isset($user)) {
      $userlist = file("users.inc.php");

      $fd = fopen("users.inc.php","w");

      fputs($fd, "<?php die(\"Access Restricted\"); ?>\n");

      for ($i=1; $i<count($userlist); $i++) {
         list($n,$p,$a) = explode(':',$userlist[$i]);
         if (!in_array($n,$user)) {
            fputs($fd,$userlist[$i]);
         }
      }
      fclose($fd);
   }
   header("Location: $HTTP_REFERER");   
?>


admin_adduser.php
Code:

<?php
   include "auth.inc.php";
   verifyAccess(0);
?>
<html>
<head>
<title>Add User</title>
<style>
   TD.HEAD   { font-family : Arial; font-weight: bold; font-size: 9pt; color: white; background: black; }
   TD.ROW   { font-family : Arial; font-weight: normal; font-size: 9pt; color: black; background: white; }
   TD.FOOT   { font-family : Arial; font-weight: normal; font-size: 9pt; color: black; background: #DDDDDD; text-align:center}
</style>
</head>
<body>
<font face="Arial" size=2>
<?php
   if (!isset($submit)) {
?>
<table border=1 width="95%">
<tr><td colspan=2 align=center class="HEAD"><b>Add User</b></td></tr>
<form>
<tr><td class="ROW">Username </td><td class="ROW"> <input name="name" size=10></td></tr>
<tr><td class="ROW">Password </td><td class="ROW"> <input name="pass" size=10></td></tr>
<tr><td class="ROW">Access Level </td><td class="ROW"> <input name="level" size=10 value></td></tr>
<tr><td colspan=2 class="FOOT"><input type=submit name="submit" value=" Set "></td></tr>
</form>
</table>
<?php
   } else {
      $userlist = file("users.inc.php");
      $done  = false;
      $auth  = false;
      $found = false;
      $i = 0;
      while ((!$found) && ($i<count($userlist))) {
         $i++;
         list($n,$p,$a) = explode(':',$userlist[$i]);
         $found = ($n==$name);
      }
      if ($found) {
         echo "Error: Username <i>$name</i> already exists<br><br>";
         echo "<a href=\"javascript: history.back();\">Back</a>";
         
      } else {
         $p = md5($name.$pass);
         $a = $level;
         $i = count($userlist);
         $userlist[$i] = implode(':',array($name,$p,$a));
         sort($userlist);
         $fd = fopen("users.inc.php","w");
         fputs($fd,"<?php die(\"Access restricted\"); ?>\n");
         for ($i=1; $i<count($userlist); $i++) {
            fputs($fd,chop($userlist[$i])."\n");
         }
         fclose($fd);
         echo "<script>window.opener.document.location.reload(); window.close();</script>";
      }
   }
?>
</font>
</body>
</html>   


admin.php

Code:

<?php
   include "auth.inc.php";
   verifyAccess(0);
?>
<html>
<style>
   TD.HEAD   { font-family : Arial; font-weight: bold; font-size: 9pt; color: white; background: black; }
   TD.ROW   { font-family : Arial; font-weight: normal; font-size: 9pt; color: black; background: white; }
   TD.FOOT   { font-family : Arial; font-weight: normal; font-size: 9pt; color: black; background: #DDDDDD; text-align:center}
</style>
<script>
   function editUser(n) {
      url = "admin_edituser.php?name="+n;
      var dummy = window.open(url,"EditUser","width=300,height=130");
   }
   function delUser(n) {
      url = "admin_deluser.php?name="+n;
      var dummy = window.open(url,"DelUser","width=300,height=130");
   }
   function addUser() {
      url = "admin_adduser.php";
      var dummy = window.open(url,"AddUser","width=300,height=160");
   }
   function delChecked() {
      document.forms[0].submit();
   }
</script>
<body>
<table border=1 width=400>
<tr><td colspan=4 align=center><font face="Arial" size=3><b>Authorizer 1.0 - User admin</b></font></td></tr>
<form action="admin_delchecked.php" method=post>
<tr><td class="HEAD" width=20>&nbsp;</td><td class="HEAD" width=230>Username</td><td class="HEAD" width=50>Level</td><td class="HEAD" width=100>Action</td></tr>
<?php
   $userlist = file("users.inc.php");
   for ($i=1; $i<count($userlist); $i++) {
      list($n,$p,$a) = explode(':',chop($userlist[$i]));
      echo "<tr>";
      echo "<td class=\"ROW\"><input type=checkbox name=\"user[]\" value=\"$n\"></td><td class=\"ROW\">$n</td><td class=\"ROW\">$a</td><td class=\"ROW\" align=center><a href=\"javascript: editUser('$n');\">Edit</a> - <a href=\"admin_deluser.php?name=$n\">Delete</a></td>";
      echo "</tr>\n";
   }
?>
</form>
</table>
<table border=1 width=400>
<tr><td class="FOOT" width=133><a href="javascript: delChecked();">Delete Checked</a></td><td class="FOOT" width=134><a href="javascript: addUser();">Add User</a></td><td class="FOOT" width=133><a href="auth_logout.php">Logout</a></td></tr>
</table>
</body>
</html>

[/code]
david150
You can also use Content Management Systems like phpnuke, with that you have an adminstration panel and a lot more and its for free. Wink
grief
mathiaus wrote:
If you know php though make your own. It's better!


I agree, creating your own scripts is always the best - that way i's more customizable to your own needs.
misterdimiz
Wow gmcclure! You've made a good work. Thanks for the tip.
Related topics
Windows Vista Official Thread
Free php Editor
Adding PHP to My HTML site
Login, database en ban
Can l get my web site to have a shared login?
Password problem
how do i make a login page
Automatic download start !!
Chat and Login scripts
Login Script
Login Scripts..
tables or div ?
linux desktop memory requirements
m-productions homepage TEMP
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.