Web Hosting Vodahost    

Home Take The Royal Tour! Order Now Features Prices
Go Back   Web Hosting > BlueVoda Website Builder Forums > BlueVoda Tips, Tricks and Shortcuts

Notices

BlueVoda Tips, Tricks and Shortcuts Know a great BlueVoda (or Web design) tip or trick? Share it with the world here. Become famous for your brilliance! Please, No Questions or Problems!

Reply
 
LinkBack Thread Tools
  #1  
Old 06-28-2006, 05:01 PM
Corporal
 
Join Date: Jun 2006
Location: Belgium
Posts: 10
Post [TUTORIAL] Creating a login script for multiple users.

Have you ever wanted to make a login script so you can have membercontent?
This tutorial will show you how using php. No database will be used.

1) Creating a form
Here is the code for making the form. The form asks for your username and password. Save this code as login.php

Code:
<html>
<head>
<title>Please login</title>
</head>
<body>
<?php
if(isset($_GET["wrong"])){
echo("<b>Username or password is incorrect!<br />Please try again.</b>");
}
?>

<form action="login2.php" method="post">
<br />
Username:<br />
<input type="text" name="username" /><br />
Password:<br />
<input type="password" name="password" />
<br />
<br />
<input type="submit" value="Login" />
</form>

</body>
</html>
The piece of php code will tell the viewer that he or she typed a wrong username or password.
between the <form></form> tags we have 3 input fields. 1 for the username, 1 for the password, and 1 that will submit the inputs and send it to login2.php.
Note that the form will be sent using the "post" method. This is the safest.

2)Checking the userinput
In this step we will check if the username and password are correct.
This is done with php. No html will be used.
Create a new page and call it login2.php. Give it the following content:
PHP Code:
<?php
$usernames 
= array("user1""user2""user3""superman");
$passwords = array("pass1""pass2""password3""supermans password");
$page "mypage.php";



for(
$i=0;$i<count($usernames);$i++){
  
$logindata[$usernames[$i]]=$passwords[$i];
}
if(
$logindata[$_POST["username"]]==$_POST["password"]){
session_start();
$_SESSION["username"]=$_POST["username"];
header('Location: '.$page);
exit;
}else{
header('Location: login.php?wrong=1');
exit;
}
?>
You might want to edit the first 3 lines.
1)$usernames is an array with all the usernames. To add a new one:
PHP Code:
$usernames = array("user1""user2""user3""superman""new one"); 
2)$passwords is an array with all the passwords. To add a new one:
PHP Code:
$passwords = array("pass1""pass2""password3""supermans password""new one"); 
Make sure that the username and the password have the same position.
user1 will be able to login with the password pass1, not with any other password. user2 with pass2 and no other.
3)$page is the page the user will go to when he is logged in. Change mypage.php to the page you would like to be the main page for logged in users. make sure the quotationmarks are still around it!

3) Checking if the user is still logged in
Create a new page, call it login3.php with the following code:
PHP Code:
<?php
session_start
();
if(!isset(
$_SESSION["username"]){
header('Location: login.php');
exit;
}
?>
This code simply checks if the sesion that we made in login2.php has a value.
If it doesn't it sends you to the login page.

4) Making your pages protected
All the pages that you want to be protected need to have a .php extension! otherwise they cannot be protected. Add this piece of code to the first line.
PHP Code:
<?php require("login3.php"); ?>
Make sure it is on the first line. Otherwise it will give you an error.
Now you pages are protected! simple?


5) Extras
making a log out page:
make a new .php page and add the following contents at the very beginning:
PHP Code:
<?php session_start();session_unset();session_destroy(); ?>

Your fancy logout message here
create a link somewhere on your secured pages that leads to the logout page and the user will be logged out when he clicks the link.

An other extra: showing the user's name: just put this piece of code in any secured page where you want to show the name:
PHP Code:
<?php echo($_SESSION["username"]); ?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2  
Old 06-28-2006, 06:27 PM
Watdaflip's Avatar
Brigadier General
 
Join Date: Sep 2005
Location: Cincinnati, Ohio
Posts: 1,638
Default Re: [TUTORIAL] Creating a login script for multiple users.

Just keep in mind not to intergate this with your website using BV, because its impossible with BV to put php in before the head is declared. This is going to give you an error when using session_start();

session_start(); has to be declared on the first line of a page (or second if you count <?php) before any other header is declared
__________________

Register/Login Script
Do you use a Password Protected Directory? Need a way to allow users to make their own account, try my .htaccess Login Script
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old 06-28-2006, 07:09 PM
Corporal
 
Join Date: Jun 2006
Location: Belgium
Posts: 10
Default Re: [TUTORIAL] Creating a login script for multiple users.

If you are using BV just create your page, save it nad then open it with notepad or an other plain text editor. Now you can add the php code.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old 07-11-2006, 06:41 AM
Private First Class
 
Join Date: Jun 2006
Posts: 9
Default Re: [TUTORIAL] Creating a login script for multiple users.

Quote:
Originally Posted by nbop
If you are using BV just create your page, save it nad then open it with notepad or an other plain text editor. Now you can add the php code.
sir,
will you please tell me how can l use the above script if I am using blue
voda.
How to save the pages as .php extension
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old 07-11-2006, 07:31 AM
Pablo's Avatar
Moderator
 
Join Date: May 2005
Posts: 510
Default Re: [TUTORIAL] Creating a login script for multiple users.

Quote:
Just keep in mind not to intergate this with your website using BV
Yes, you can insert this code directly into BV:
View->Page HTML->Start of Page
__________________
Forum Moderator
BlueVoda Specialist
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old 07-11-2006, 02:57 PM
navaldesign's Avatar
General & Forum Moderator
 
Join Date: Oct 2005
Location: Italy
Posts: 9,129
Default Re: [TUTORIAL] Creating a login script for multiple users.

Only one observation: the usernames and passwords in this script are hardcoded in the script itself. This means that the script - login2.php - needs to be edited manually everytime a new user must be added. This is not so convenient, if you expect to have many visitors. There will also be a "dead" time before the site administrator updated the script.
A solution would be offcourse to use a database, or, have the registration form info (username and password) writen in an file, wich could be in this way automatically updated.

However, very useful!. Well done mate!
__________________
Navaldesign
Logger Lite: Low Cost, Customizable, multifeatured Login script
Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old 07-13-2006, 04:24 PM
Private First Class
 
Join Date: Jun 2006
Posts: 9
Default Re: [TUTORIAL] Creating a login script for multiple users.

I have got the downlodable pages from form maker now where to upload these pages and how to upload.

should it be upload thru publishing blue voda or
blue ftp or cpanel file manager.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old 07-13-2006, 04:33 PM
navaldesign's Avatar
General & Forum Moderator
 
Join Date: Oct 2005
Location: Italy
Posts: 9,129
Default Re: [TUTORIAL] Creating a login script for multiple users.

Read the installation instructions here
__________________
Navaldesign
Logger Lite: Low Cost, Customizable, multifeatured Login script
Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9  
Old 07-16-2006, 11:34 PM
Private
 
Join Date: Jul 2006
Posts: 3
Thumbs up Re: [TUTORIAL] Creating a login script for multiple users.

Thanks nbop and other member for the tutorial creating vbmenu_register("postmenu_48386", true); login for multiple user, however, have created this on my site but donīt know what to do next, what area of my cpanel will i load this into as i am using cpanel and how do i create an account for the user so that as soon as he signin he will see his information, secondly do i need to create database for the login form and who. i will hope to hear from you soon about this
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #10  
Old 07-17-2006, 05:44 AM
navaldesign's Avatar
General & Forum Moderator
 
Join Date: Oct 2005
Location: Italy
Posts: 9,129
Default Re: [TUTORIAL] Creating a login script for multiple users.

I'm afraid that the above script is not so automated. After a user has registered, you have to MANUALLY insert his username and password in the script as described above. Then you must upload again the updated script to your server and then let the new member know that he / she can go on visiting your site. Till you do this, he / she won't be able to loggin.
You don't need to create a database, not with this script.
__________________
Navaldesign
Logger Lite: Low Cost, Customizable, multifeatured Login script
Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #11  
Old 07-18-2006, 12:21 AM
Private
 
Join Date: Jul 2006
Posts: 3
Default Re: [TUTORIAL] Creating a login script for multiple users.

Thanks for the reply what i am saying about is this, i have a site which have a registration page and login page, when a user register his information to the site throught eh login page what do i do next and how do i direct his register information to a page he will see when he login, i have don the pages discribe before but i want to know how i can setup a database for it as i am using cpanel
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #12  
Old 07-18-2006, 05:17 AM
navaldesign's Avatar
General & Forum Moderator
 
Join Date: Oct 2005
Location: Italy
Posts: 9,129
Default Re: [TUTORIAL] Creating a login script for multiple users.

The above script doesn't make use of a database. Also, it doesn't describe how to make a registration form. You need to
1. Create aregistration form where the user fills in his desired username and password along with other information. Set the form so that the info is sent to you through an email. Update the script with the new username and password, and re-upload it on the server. Let the user know that his registration has been approved and he may now loggin in your site.
__________________
Navaldesign
Logger Lite: Low Cost, Customizable, multifeatured Login script
Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #13  
Old 07-21-2006, 08:46 PM
Staff Sergeant
 
Join Date: Jun 2006
Posts: 43
Default Re: [TUTORIAL] Creating a login script for multiple users.

This script can be inserted into a Blue Voda page simply by using the html tool at the top of the left toolbar to insert an html box. Double-click the box to open it and paste in the code. The php code will be embedded in the page. However, there seems to be a problem with the script. This appears above the form fields for the Name and Password before and information is entered:

Username or password is incorrect!
Please try again.</B>"); } ?>
__________________
No matter how fast you are going, there is always someone trying to pass.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #14  
Old 07-21-2006, 09:02 PM
Staff Sergeant
 
Join Date: Jun 2006
Posts: 43
Default Re: [TUTORIAL] Creating a login script for multiple users.

also tried this by uploading the php file to my server. When I ran it I got the following error:
Parse error: syntax error, unexpected '}', expecting ',' or ';' in /home/colescom/public_html/FormTools/phptest.php on line 8 Areany values supposed to load values supposed to be modified before running the script?
__________________
No matter how fast you are going, there is always someone trying to pass.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #15  
Old 07-24-2006, 12:39 AM
Private
 
Join Date: Jul 2006
Posts: 3
Default Re: [TUTORIAL] Creating a login script for multiple users.

Thanks i got ur explainatioon about the application form, plz can you give me step by step what files to create and what directory are needed to work all this and how do. where do i do when the information on the application form has been sent my email . what thing he see when i register user login
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #16  
Old 09-12-2006, 02:24 AM
Private
 
Join Date: Sep 2006
Posts: 1
Default Re: [TUTORIAL] Creating a login script for multiple users.

Hi...I tried to create a login using the script that was posted...I uploaded it to try it and I am receiving an error message.
The error message is saying the following:
Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /homepages/41/d171920401/htdocs/Beta_Site/login2.php on line 9

Does anyone have any suggestions what I m doing wrong?

Thanks,
John
Digg this Post!