Forum Moderators: coopster

Message Too Old, No Replies

need major help

i need some help with username redirect

         

thinkdifferent09

1:05 am on Mar 17, 2005 (gmt 0)

10+ Year Member



i am new to php... right now i would really appreciate it this if someone could just write this code for me or give me a lot of guidance ive read a lot on php and im still really confused
what i have is a secured directory on my web site and when you attempt to access it you get a windows dialog box popup asking you for your username and password, when they logon successfully all i want is for a simple php script to execute i will make the file secure i want it to be simple it needs to read 3 values from a table in mysql
the database is named "coulombenet" table name "users"
its gonna read
their "username" "password" "directory"
i want to basically do this roughly
if user = a
then read directory for user A and go there, like their web site
else (like if they dont have a directory)
go to 'no account' page... andi want to be able to search the table to find the user and go to their directory of the site automatically... all the rest is setup
currently when someone logs in it asks for their name and its designed so they cant cross names and can only click theirs
i really need someone to write this out for me
im so confused
thank you so much for your anticipated help
thanks
mat

ironik

1:36 am on Mar 17, 2005 (gmt 0)

10+ Year Member



What your asking is a relatively complex and time consuming task. From my experience, those programmers who are competent enough to write a login system will usually charge for it, I know I do.

There are, however, plenty of pre-written free scripts available. Have a search on these sites:

Sourceforge [sourceforge.net]
Hotscripts [hotscripts.com]
Freshmeat [freshmeat.net]

thinkdifferent09

2:35 am on Mar 17, 2005 (gmt 0)

10+ Year Member



well cant i make it simpler
i mean its already secure
cant i do a single page php script
that just goes
IF USER = JOHNDOE
GO TO FILE
OR IF USER = JANEDOE
GO TO FILE
ELSE GO TO FILE
cant i just do something like that? can you do that for me
that would be greatly appreciated
thanks
mat

thinkdifferent09

2:38 am on Mar 17, 2005 (gmt 0)

10+ Year Member



let me rephrase
this might make it easier
its 3 users
i jsut want it to do this
IF USER = MAT
GO TO "MAT'S PAGE"
IF USER = BEA
GO TO "BEA'S PAGE"
IF USER = GARY
GO TO "GARY'S PAGE"
ELSE GO TO
END IF
now how can u do that in PHP code thats what i need

ironik

3:25 am on Mar 17, 2005 (gmt 0)

10+ Year Member



Ok, this is how you would write the code... very basically. I'm not sure where your username is coming from, so I've just called it $username. If you are using http authentication, maybe someone else can post an example of getting the username from there.


<?php
$username = 'mat';

switch ($username)
{
case 'mat':
header ('location: [mydomain.com...]
break;

case 'bea':
header ('location: [mydomain.com...]
break;

case 'gary':
header ('location: [mydomain.com...]
break;

default:
header ('location: [mydomain.com...]
break;
}
exit();
?>

That will divert to a folder depending on the value of $username.

thinkdifferent09

3:36 am on Mar 17, 2005 (gmt 0)

10+ Year Member



oh thank you so much
im getting the username from a windows dialog popup box asking for the uname/pw... does that help with the variable
thank you so much for your help
mat

ironik

4:04 am on Mar 17, 2005 (gmt 0)

10+ Year Member



After a little hunting around on php authentication, it's alot easier than I thought. PHP has some inbuilt variables available. Try this:


<?php
if (isset($_SERVER['PHP_AUTH_USER']))
{
$username = $_SERVER['PHP_AUTH_USER'];
switch ($username)
{
case 'mat':
header ('location: [mydomain.com...]
break;

case 'bea':
header ('location: [mydomain.com...]
break;

case 'gary':
header ('location: [mydomain.com...]
break;

default:
header ('location: [mydomain.com...]
break;
}
exit();
} else {
header('WWW-Authenticate: Basic realm="My Realm"');
header('HTTP/1.0 401 Unauthorized');
echo 'You are not authorised to access this page';
exit;

}
?>

You'll have to change "My Realm" to your http authentication realm name or just remove that part altogether if you don't need it.

thinkdifferent09

4:24 am on Mar 17, 2005 (gmt 0)

10+ Year Member



that doesnt work... i got it to work at least if i set the variable myself so i know the rest works
does it help to know that the server is running freebsd... i do know those commands are apache related that you wrote
mat

ironik

4:38 am on Mar 17, 2005 (gmt 0)

10+ Year Member



Yeah, sorry.. they are apache only. The variables don't exist on other server types (CGI etc), as far as I am aware.

henry0

12:26 pm on Mar 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In addition to:
What you are asking is a relatively complex and time-consuming task. From my experience, those programmers who are competent enough to write a login system will usually charge for it, I know I do.

Money exchange on the forum is not really relevant
What matters is that such a script may call and certainly will for classes and functions and a good MySQL understanding so even writing it for you does not help you to become a better PHP coder.

Try to get a better PHP understanding
And come back with some script draft, then many members will point to your errors and suggest fixes

Have fun!