Forum index / Computers / Login system

Login system

15 posts · page 1 of 1

post #1
01 March 2005, 12:23 UTC#1
Does anyone know any free or trial versions of applications that allow you to run a log in script on your website, which allows user to register, have access to specific pages etc.

If anyone knows any details on this, it would be a big help.

Cheers

Nico
post #2
01 March 2005, 12:37 UTC#2
lol that is very difficult shit mate

if someone knows for 1 I want it too

I dont even know how to install I though
post #3
01 March 2005, 16:00 UTC#3
Yus, the following is not for the faint hearted:

To Start the session:

CODE <?
session_start(); // start session tag
?>
<!-- header tags, edit to match your own, or include() template header file. -->
<html>
<head>
<title>Login</title>
<head>
<body>
<?


Thats to be inserted inside the index page, for reference you will have to rename all your files .php, you can do this by renaming the extension inside your ftp client, via notepad or dreamweaver.



Check user:

Now the script needs to check whether the client is logged in or not, if they are let them be, if not pop up a login box.

CODE if(!isset($username) | !isset($password)) {
// exit php mode
?>
<form action="<?=$PHP_SELF?><?if($QUERY_STRING){ echo"?". $QUERY_STRING;}?>" method="POST">
<p align="center">Members only. Please login to access this document.</p>
<table align="center" border="0">
<tr>
 <th>
Username:
 </th>
 <th>
<input type="text" name="username">
 </th>
</tr>
<tr>
 <th>
Password:
 </th>
 <th>
<input type="password" name="password">
 </th>
</tr>
<tr>
 <th colspan="2" align="right">
<input type="submit" value="Login">
</form>
 </th>
</tr>
</table>
</body>
</html>
<?
exit();
}


Verify user:

CODE // everything successfull so far?

session_register("username");
session_register("password"); // register username and password as session variables.

// Here you would check the supplied username and password against your database to see if they exist.
// For example, a MySQL Query, your method may differ, obviously you would make a dataabse connection first.

$sql = mysql_query("SELECT password FROM user_table WHERE username = '$username'");
$fetch_em = mysql_fetch_array($sql);
$numrows = mysql_num_rows($sql);

if($numrows != "0" & $password == $fetch_em["password"]) {
$valid_user = 1;
}
else {
$valid_user = 0;
}


IF all the info is correct:

CODE // If correct don't show login box
// If info can't be found....

if (!($valid_user))
{
session_unset();   // Unset session variables.
session_destroy(); // End Session we created earlier.
// escape from php mode.
?>
<form action="<?=$PHP_SELF?><?if($QUERY_STRING){ echo"?". $QUERY_STRING;}?>" method="POST">
<p align="center">Incorrect login information, please try again. You must login to access this document.</p>
<table align="center" border="0">
<tr>
 <th>
Username:
 </th>
 <th>
<input type="text" name="username">
 </th>
</tr>
<tr>
 <th>
Password:
 </th>
 <th>
<input type="password" name="password">
 </th>
</tr>
<tr>
 <th colspan="2" align="right">
<input type="submit" value="Login">
</form>
 </th>
</tr>
</table>
</body>
</html>
<?
exit();
}


Logging out:

CODE <?
session_start();
session_unset();
session_destroy(); // session destruct
?>
<html>
<head>
<title>Logged Out</title>
</head>
<body>
<p align="center">You have been logged out.</p>
<p align="center"><a href="members.php">Log back in</a> | <a href="index.php">Go to homepage</a></p>
</body>
</html>


login.php:

CODE <?
session_start(); // start session.
?>
<!-- header tags, edit to match your own, or include template header file. -->
<html>
<head>
<title>Login</title>
<head>
<body>
<?
if(!isset($username) | !isset($password)) {
// escape from php mode.
?>
<form action="<?=$PHP_SELF?><?if($QUERY_STRING){ echo"?". $QUERY_STRING;}?>" method="POST">
<p align="center">Members only. Please login to access this document.</p>
<table align="center" border="0">
<tr>
 <th>
Username:
 </th>
 <th>
<input type="text" name="username">
 </th>
</tr>
<tr>
 <th>
Password:
 </th>
 <th>
<input type="password" name="password">
 </th>
</tr>
<tr>
 <th colspan="2" align="right">
<input type="submit" value="Login">
</form>
 </th>
</tr>
</table>
</body>
</html>
<?
exit();
}

// If all is well so far.

session_register("username");
session_register("password"); // register username and password as session variables.

// Here you would check the supplied username and password against your database to see if they exist.
// For example, a MySQL Query, your method may differ.

$sql = mysql_query("SELECT password FROM user_table WHERE username = '$username'");
$fetch_em = mysql_fetch_array($sql);
$numrows = mysql_num_rows($sql);

if($numrows != "0" & $password == $fetch_em["password"]) {
$valid_user = 1;
}
else {
$valid_user = 0;
}

// If the username exists and pass is correct, don't pop up the login code again.
// If info can't be found or verified....

if (!($valid_user))
{
session_unset();   // Unset session variables.
session_destroy(); // End Session we created earlier.
// escape from php mode.
?>
<form action="<?=$PHP_SELF?><?if($QUERY_STRING){ echo"?". $QUERY_STRING;}?>" method="POST">
<p align="center">Incorrect login information, please try again. You must login to access this document.</p>
<table align="center" border="0">
<tr>
 <th>
Username:
 </th>
 <th>
<input type="text" name="username">
 </th>
</tr>
<tr>
 <th>
Password:
 </th>
 <th>
<input type="password" name="password">
 </th>
</tr>
<tr>
 <th colspan="2" align="right">
<input type="submit" value="Login">
</form>
 </th>
</tr>
</table>
</body>
</html>
<?
exit();
}
?>


Logout.php:

CODE <?
session_start();
session_unset();
session_destroy(); // destroy session.
?>
<html>
<head>
<title>Logged Out</title>
</head>
<body>
<p align="center">You have been successfuly logged out.</p>
<p align="center"><a href="members.php">Log back in</a> | <a href="index.php">Go to homepage</a></p>
</body>
</html>


So put all that code in a file called members.php, unless stated otherwise, and on the page you want someone to login type the following:

CODE include($DOCUMENT_ROOT .'/includes/login.php');  // put in includes


Note, put the .php documents in /includes/file so members.php, login.php, logout.php all go inside /includes.

you will need a php4 enabled webserver to do this with, and ALL documents will need renaming to .php
post #5
01 March 2005, 16:12 UTC#5
cheers gman, ill see if it works.
post #6
01 March 2005, 16:24 UTC#6
Yus, do it in test documents for now, say like yourdomain.com/test/ and make up some test files, I'm not sure on how extensive that markup is, if you want I'll test it tonight and send you the docs, whichever :P
post #7
01 March 2005, 16:32 UTC#7
well it's not actually for me it's for a friend, so I'll need to send him the coding over msn when he gets on. But yeah if you could test it, that would be really helpful.
post #8
01 March 2005, 16:45 UTC#8
fuck that shit
post #9
01 March 2005, 16:57 UTC#9
lol, I've seen alot worse before.
post #11
01 March 2005, 18:04 UTC#11
Yus, thats only scratching the surface
post #12
01 March 2005, 18:13 UTC#12
a Vee Oh whut?
post #13
01 March 2005, 18:14 UTC#13
VOW?
post #14
01 March 2005, 18:22 UTC#14
I believe its what real estate agents use for their website property management, and listing shizzle, like searching of properties, and the actual "CMS" that powers submissions etc
post #15
01 March 2005, 18:51 UTC#15
ah rite, well I have no need for that lol