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


how do i create a Member access page





ligho
hello to you all.
I'm tring to creat a website where only members with password are allowed to gain access.Which software do you think will do the job best for me.
Roald
Learn PHP and MySQL and you'll be able to do that, if you're looking for a tutorial, I'm sure you'll find them at the tutorial or PHP and MySQL section (as the answer on your question too).
alalex
try looking up in google to a good opensource precoded web to login, in case you don't want to code it up.
If you know a bit about php for example, get dreamweaver and if you are able to set up a dynamic site and a mysql databas (frihost provides both, and if you dont know how to use them go to the admin panel http://yourserver.frih.net/config/) once you have set up all that, configure dreamweaver to create dynamic content, and it will code up all you need.

In case you know php and mysql, create a database for the users or passwords or both. Program in php to select frim the database to check wether they are registered or not, and then create a new session variable to store some value like "logged" or something like that. This was just he easiest way.
Im going to post in a few minutes a code i used to create a login. If you like it use it, or not if you dont, you can edit it to fit your needs.. mine uses only a password, so its easier to program it... i will also post how to add username to it.
b4r4t
On tutorialized.com there are lot of PHP tutorials (including logging) ... but - it's better to know a little PHP before You start to make such thing ...

Best will be a book... in my opinion one of the best books is :

Beginning PHP5, Apache, MySQL Web Development

http://www.amazon.com/exec/obidos/ASIN/0764579665/helion-20

Good way to start PHP and MySQL Smile

Well explained on practical examples.
The thing You want (Login) is included too , than reading this book you learn how to do it, and much more. You may give it a try Smile
alalex
here a file named "functions.php" it contains some very useful php functions for identification and display status as logged or not logged:
Code:
<?php
//Function page

//Display status
function display_status(){
   $script = $_SERVER['PHP_SELF'];
   $path_info = pathinfo($script);
   $link = $path_info['basename'];
   if($_SESSION['logged'] == true){
      $status = $_SESSION['logged'];
      echo '<a href="identificacion.php?target='.$link.'" class="white">'.$status.'</a>';
   }else{
      $_SESSION['logged'] = 'Not logged';
      $status = $_SESSION['logged'];
      echo '<a href="identificacion.php?target='.$link.'" class="white">'.$status.'</a>';
   }
}

//function to connect to a database
//In case of error it will email a determined email
function connect_db($username,$password,$host){
   $connection = mysql_connect($host,$username,$password);
   if($connection == false){
      echo 'Impossible to stablish connection';
      $error_num = mysql_errorn();
      $error_code = mysql_error();
      mail('destination mail','Email subject',"Error code: $error_num _\nError: $error_code");
      return false;
   }else{
      return true;
   }
}

//function to check if username/password exist
function select_id($name,$pass){
   mysql_select_db('db_name');
   $query = "SELECT ((fields separated with comas)) FROM `table` WHERE `pass`='$pass'";
   $result = mysql_query($query);
   if (!$result) {
      $_SESSION['logged'] = 'Not logged';
      $message = 'Wrong query: '.$query.'<br>Error description: '.mysql_error();
      mail('email destination','mail subject',$message,'From:who');
      echo '<p><img src="imagenes/iconos/warn.png" alt="Error" align="absmiddle">&nbsp;Sorry but there was an error.</p>';
      return false;
   }else{
      if(mysql_num_rows($result) == 1){
         while($row = mysql_fetch_array($result)){
            echo 'Identified!<br>';
            echo '<img src="../../imagenes/iconos/bullet_go.png" alt="Continue" width="16" height="16" border="0" align="absmiddle"><a href="identificacion.php" class="blue">Continue</a>';
            $_SESSION['logged'] = 'logged';
         }
         return true;
      }else{
         $_SESSION['logged'] = 'Not logged';
         echo '<img src="imagenes/iconos/warn.png" alt="Error" width="16" height="16" border="0" align="absmiddle">wrong pass/user.<br>';
         echo '<a href="identificacion.php" class="blue">Return</a>';
         return false;
      }
   }
}

//Check if a user has permissions to enter a page, returns true or false
function check_access(){
   $status = $_SESSION['logged'];
   if($status == 'logged'){
      return true;
   }else{
      echo 'You must identify yourself to view this page<br>';
      echo '<img src="../../imagenes/iconos/key.png" alt="login" width="16" height="16" border="0" align="absmiddle">&nbsp;<a href="identificacion.php" class="blue">Go to login page</a>';
      return false;
   }
}
?>

When i originally programmed all this, i did it in spanish, so had to translate it. sorry if some of the code is in spanish, i tried to translate it...

Name your login page "identificacion.php" and then in all the pages you are going to use put in the first line, before any other thing, even before the html code:
Code:
<?php
//start a session and require the function page
session_start();
require 'functions.php';
?>


Now, in your webs, you can display current status with only writing display_status(), and in all the pages you want to allow only registered users put in the content you want to hide this starting tag:
Code:
<?php
if($_SESSION['logged'] == 'logged'){
?>
...here all the html code for allowed users...
<?php
}else{
?>
...all the html here for not registered users, remember that the function creates the code by itself
<?php
}
?>


Once you get it to work, test it a few times in all possible cases, then you got it!
remember to check all the code to adapt it to you web.
Ask me through this post about all the errors you get with that code!
alalex
to use the code i gave you up there, first create two files, one called identificacion.php where you need to have a form with username, password fields, and then another like connect.php where you store the variables sent through the form using the $_POST[] variable in php, and use the function i gave you up there to log in or not.
you also need the most important file, functions.php, which will contain ONLY the code i gave you i said it was for functions, remember, no html in that file!
then, i think that with basic php knowledge you will be able to use it...
ask me any doubt you have! Very Happy
Related topics
Help me please...frontpage help needed!
You don't have permission to access / on this server.
nice webpage
I Need Help For Intro Page On My Site
Creating a page with php
Abitur Page '07
general css page for a site
Access DataBase using visual basic6
Wordpress Redirecting links
[VB.NET] Open a page using IE cookies
data access page in the internet
Automatic index
member profile page
Wordpress and permission to access page
Reply to topic    Frihost Forum Index -> Webmaster and Internet -> Design Tips

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