Php login script needed

hi everybody,

i am looking for a php login script that send users depending on their login to a login specific site.

its supposed to be a client area.

example: there is a login form on the website (html not flash), t he client enters his given username and password an will be transported to the site specified for him. client a gets to see client a site, client b gets to see client b site. i hope this is not too confusing.

i found the following script which uses .htaccess and a form, but unfortunatly it doesn’t work with multiple logins.

$server = "www.yourdomain.com/protecteddirectory/";

 if(isset($HTTP_POST_VARS['username']))
 {
      $username = $HTTP_POST_VARS['username'];
 }
 
  if(isset($HTTP_POST_VARS['password']))
 {
      $password = $HTTP_POST_VARS['password'];
 }
 
 ?>
 <script>
function redirect()
{
window.location.replace("http://<?=$username?>:<?=$password?>@<?=$server?>");
}
setTimeout("redirect();", 1000);

can anybody help? i don’t have much experience with programming stuff.

thanks,
funkyfly

Depends on how much users you want to have access. For a couple of users, it’s not so hard:


<?

$username = $_POST['username'];
$password = $_POST['password'];

if ($username = "User 1" && $password = "User 1 password"){
header("Location: http://www.yourserver.com/user1page.html");
}

if ($username = "User 2" && $password = "User 2 password"){
header("Location: http://www.yourserver.com/user2page.html");
}

if ($username = "User 3" && $password = "User 3 password"){
header("Location: http://www.yourserver.com/user3page.html");
}
?>

That should do it. If it doesn’t work, I’ll leave this to JubJub :slight_smile: Remove the a href stuff, only keep the http:// address, so that it become **“Location: url”**The whole a href part is autmoatically added. That’s kinda annoying :-\

hi voetsjoeba,

thanks a lot for you reply and help. sorry to ask such stupid questions but where do i store the users and passwords. this doesn’t work with .htaccess anymore. the script should handle different directories. (clients/client a or clients/client b)

do i store it in the php file? if so it would seem pretty unsecure. doesn’t it?

the script should handle only a few users (5). does this script ensure that user a can’t see user b stuff?

i will never learn that stuff :frowning:

greets,
funkyfly

Well, the php script can’t be viewed by the browser, especially not because it will redirect very fast. And by the way, that’s no stupid question :). The passwords should be ‘stored’ inside your users brains. You should tell them the user name and password which they can use to go to their page. And if your users do not pass them along, they won’t get to see the other’s pages.

The directories are no problem at all. Just replace the link (http://www.yourserver.com/userpage1.html) with any link you want.

it’s me again :slight_smile:

i’m doing something wrong i guess, because its not working. here is the code i use:



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
	<title>Untitled</title>
</head>

<body>
<form action="phplogin.php" method="post">
<input type="text" name="username">
<input type="password" name="password">
<input type="submit" value="Submit">
</form>


</body>
</html>
```php
 

the phplogin:


```php

<?php
<?

$username = $_POST['username'];
$password = $_POST['password'];

if ($username = "test" && $password = "test"){
header("Location: "http://www.mydomain.com/clients/clientsa/index.html/");
}

if ($username = "test1" && $password = "test1"){
header("Location: "http://www.mydomain.com/clients/clientsb/index.html/")
}
>

maybe i can’t get the php quotes right?

funkyfly

header() has to go before any HTML

You used " inside other ones, which makes PHP think that the location to go to has already ended at “Location :”. This should work:


<?

$username = $_POST['username'];
$password = $_POST['password'];
$user1url = "http://www.mydomain.com/clients/clienta/index.html";
$user2url = "http://www.mydomain.com/clients/clientb/index.html";
$user3url = "http://www.mydomain.com/clients/clientc/index.html";

if ($username = "test" && $password = "test"){
header("Location: $user1url");
}

if ($username = "test2" && $password = "test2"){
header("Location: $user2url");
}

if ($username = "test3" && $password = "test3"){
header("Location: $user3url");
}

?>

This should be placed entirely BEFORE the HTML code. Use this for your form: action="

<? echo($PHP_SELF) ?>

". It should work when doing that.

this is really driving me nuts :hangover:

i don’t know if it is too much but could send me the file by mail? the php file and the form, i just can’t get it to work

i still don’t get it. i feel like a dumb *** :frowning:

mail

thanks for your help. thats a really cool community.

funkyfly

I’d love to, but my host is down for the moment. I’ve attached the php file that should do it.

thanks for the file, i really appreciate your help but something is still wrong.

take a look at test link

i renamed the pass.php into index.php and uploaded it there, but it automatically redirects to user3url without even showing the form? i don’t get the chance to login.

funky

Oh well, let’s just do it the good ol’ fashion way then. Make sure to upload them both in the same directory, or else change the link to the php file in the html.

well what can i say? i’m starting to feel really dumb.

you probably won’t believe but it’s still not working. regardless of the pass i enter i’m getting the clientc page (login nr. 3)

i mean, i took your files uploaded them to the same directory and tried. i don’t see why i screw up.

if you give up i can understand :wink:

funkyfly

You did fill in the html file right ?

what you mean by that?

Well, you have to fill in the fields in the HTML file and click submit for it to work.

yeah, i dit that. just renamed pass.html to index.html

Weird. Can you tell me where you’ve put it online ?

sure! you can find it here

btw, i removed one of the users to see if it makes any difference. now its redirecting mit to $user2url

Replace pass.php please, it prints the inputted data. Just to test.