Zubrag.com
May 22, 2012, 06:14:42 am *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: password protect - redirect and regular  (Read 4888 times)
impelus
Newbie
*
Posts: 8


« on: January 26, 2007, 01:58:21 am »

hello all.

i am using the script to let users select an area of the website and then login. based on the area they select (via a dropdown), they enter a password and then are directed to the site.

the problem is, is once they get to the page, they are forced to enter there password again.
(it is also password protected because I do not want anyone to be able to type in the address and access it.)

is there any way on all the sub pages of the site to check if the user is logged in and allow access or redirect to main login page?

i see there is a new groups user version of the script and maybe i need that. let me explain my setup a little more and maybe you can help give me some guidance.

/home - main login page.
/home/A - user selects A from dropdown and password and is directed to this site. this password should only be valid for this section of the website.
/home/B - same as above if user selects B from the dropdown.
/home/C

Logged
zubrag
Administrator
Hero Member
*****
Posts: 753


WWW
« Reply #1 on: January 26, 2007, 05:28:26 am »

Yes, you can use "user groups" version of the script for this.

For your example you want 3 different user groups: A, B, and C. Each group will be listed in separate file, like
groupA.php - users list for A
groupB.php - users list for B
groupC.php - users list for C
loginA.php - password check/login form for A (copied from password_protect.php, it will include groupA.php as users list)
loginB.php - password check/login form for B (copied from password_protect.php, it will include groupB.php as users list)
loginC.php - password check/login form for C (copied from password_protect.php, it will include groupC.php as users list)

/home - main login page.
You'll need to have login form (for example loginAll.php, copied from password_protect.php) including all user lists (groupA.php, groupB.php, groupC.php).
So users from all groups will be able to login here.

/home/A - user selects A from dropdown and password and is directed to this site. this password should only be valid for this section of the website.
This area will be protected by loginA.php. If user logged in on /home page, then password will not be asked again. But if user access this site area directly then user will be asked to login.

/home/B - same as above if user selects B from the dropdown.
This area will be protected by loginB.php.

/home/C
This area will be protected by loginC.php.

Note: if user logged in for A, one will not be able to access B, and C.
Logged
impelus
Newbie
*
Posts: 8


« Reply #2 on: January 27, 2007, 08:18:26 pm »

thanks.

I will look into that script.

I want to make the redirect portion work a little differently. I don't code too much in PHP, so unsure how to input this if/then statement

validate username/password set

if username = user1
redirect http://site.com/main/user1folder

if username = user2
redirect http://site.com/main/user1folder

if username = adminuser
redirect http://site.com/main

also might eventually want to add multiple users for each redirect
Logged
zubrag
Administrator
Hero Member
*****
Posts: 753


WWW
« Reply #3 on: January 28, 2007, 04:24:54 am »

For redirection look here: http://www.zubrag.com/forum/index.php?topic=67.0
Logged
impelus
Newbie
*
Posts: 8


« Reply #4 on: January 28, 2007, 10:50:19 pm »

i did. and are able to use that script if I wanted to redirect to a folder/file that included the username or password within the web address.

my question, is if anyone knows how to setup a if/then statement. of course for my users, i could have thier username be the same as the folder, but... i still would kind of have a problem

we are trying to setup an artwork site.

user one needs to access  /artwork/user1. right now there is only one user, so i could make the redirect say www.mysite.com/artwork/$username

but i also want an admin to login, and the only way to make that work, is if the username is a sybol that does not change to a subfolder - like # or ?

i also have a user that i would like to login to mysite.com/inventory  and one for mysite.com/upload.

to make this all happen, i would either need to setup multiple login pages, or put an if/then statement in the login page.

just need someone with more php knowledge with me.
Logged
impelus
Newbie
*
Posts: 8


« Reply #5 on: January 29, 2007, 12:05:55 am »

asked around. and i found a solution


Code:
<?php
if ($login == 'username1' OR $login == 'username2') {
header('Location: http://www.site.com/art/folder1');
exit;
}
elseif (
$login == 'username3') {
header('Location: http://www.site.com/files/folder');
exit;
}
elseif(
$login == 'admin') {
header('Location: http://site.com/files');
exit;
}
?>
Logged
zubrag
Administrator
Hero Member
*****
Posts: 753


WWW
« Reply #6 on: January 29, 2007, 04:49:13 am »

Glad you found solution.
The same things could be accomplished using slightly modified example from the thread I gave you link to:

$REDIRECTS = array(
  'username1' => 'art/folder1',
  'username2' => 'art/folder1,
  'username3' => 'files/folder',
  'admin' => 'files'
);

Than add following at the very bottom of the script, just before the ?> line
header('Location: http://www.site.com/'.$REDIRECTS[$login]); exit;

This approach make code more clear, since redirects are not mixed up with php code. Please note only suffix is added in the REDIRECTS array rather than whole URL (and base url placed in the redirection code).
Logged
impelus
Newbie
*
Posts: 8


« Reply #7 on: January 29, 2007, 08:56:32 am »

i agree. i will test out yours later. thanks.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC