Members Area

Soldato
Joined
15 Dec 2004
Posts
3,819
Hi,

As some of you may remember I have been doing a website for a friend a while ago now and this got put to one side over the christmas break and I've only just found time to get it finished :o Basically, I need to create a members area (It's an art website so I don't want everybody hogging my bandwidth) so only authorsied people can download files but not sure how to implement one.

I have a hosting account with tsohost which gives me three databases, two of which are in use (Forum and Shop) but I want to keep the other one in case I ever get into mySQL... I have access to PHP but don't know where to start. If it needs a back-end database, the only thing I can think of doing is querying the forum database which is powered by Invision Powerboard or can it just be done in PHP?

Any help would be appreciated :)

Thanks

Ben
 
It can be done in PHP, not sure how though. You should just be able to add another table to one of the databases you already have setup you will not need to should the 3rd.

sfx
 
Thanks for the replies :) I would prefer to do it with a login box within the web page rather than .htaaccess of you know what I mean. I have been searching on the web and found this but I can't get it to work...

Code:
<?
session_start(); // start session.

$database = '*********';
$user = '**********';
$password = '*********';
$hostname = 'localhost';
$port = 50000;

$conn_string = "DRIVER={IBM DB2 ODBC DRIVER};DATABASE=$database;" .
  "HOSTNAME=$hostname;PORT=$port;PROTOCOL=TCPIP;UID=$user;PWD=$password;";
db2_connect($conn_string, '', '');
?>
<!-- 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();
}
?>

Any ideas?

Thanks

Ben
 
Trigger said:
Thanks for the replies :) I would prefer to do it with a login box within the web page rather than .htaaccess of you know what I mean. I have been searching on the web and found this but I can't get it to work...

Any ideas?

Thanks

Ben

Thats code for accessing a DB2 database using an ODBC driver; its not going to be of any use to you.
 
L33 said:
Thats code for accessing a DB2 database using an ODBC driver; its not going to be of any use to you.

Ahh, well... ...When I first used the code without that bit on top, it said it could not get it to connect to the database so I figured I needed to tell it to connect to it somewhere. I nosed around the PHP manual a bit and found that... ...looks like I did it slightly wrong :o

Any ideas what it should be?

Thanks

Ben
 
Back
Top Bottom