# Php login script needed

**URL:** <https://forum.kirupa.com/t/php-login-script-needed/23643>\
**Category:** Uncategorized\
**Created:** [June 20, 2003, 1:39pm UTC](https://forum.kirupa.com/t/php-login-script-needed/23643 "2003-06-20T13:39:55Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![funkyfly](https://avatars.discourse-cdn.com/v4/letter/f/e9bcb4/32.png) [@funkyfly](https://forum.kirupa.com/u/funkyfly)\
**Post date:** [June 20, 2003, 1:39pm UTC](https://forum.kirupa.com/t/php-login-script-needed/23643/1 "2003-06-20T13:39:55Z")

</div>

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.

```php
$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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 20, 2003, 2:21pm UTC](https://forum.kirupa.com/t/php-login-script-needed/23643/2 "2003-06-20T14:21:03Z")

</div>

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

```php

<?

$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 🙂 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 :-\

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 20, 2003, 3:41pm UTC](https://forum.kirupa.com/t/php-login-script-needed/23643/3 "2003-06-20T15:41:35Z")

</div>

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 ☹

greets,  
funkyfly

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 20, 2003, 3:51pm UTC](https://forum.kirupa.com/t/php-login-script-needed/23643/4 "2003-06-20T15:51:58Z")

</div>

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](http://www.yourserver.com/userpage1.html)) with any link you want.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 20, 2003, 4:45pm UTC](https://forum.kirupa.com/t/php-login-script-needed/23643/5 "2003-06-20T16:45:52Z")

</div>

it’s me again 🙂

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

````php

<!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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 20, 2003, 4:56pm UTC](https://forum.kirupa.com/t/php-login-script-needed/23643/6 "2003-06-20T16:56:06Z")

</div>

header() has to go before any HTML

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 20, 2003, 5:02pm UTC](https://forum.kirupa.com/t/php-login-script-needed/23643/7 "2003-06-20T17:02:49Z")

</div>

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

```php

<?

$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="

```php
<? echo($PHP_SELF) ?>

```

". It should work when doing that.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 20, 2003, 6:53pm UTC](https://forum.kirupa.com/t/php-login-script-needed/23643/8 "2003-06-20T18:53:29Z")

</div>

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 \*\*\* ☹

[mail](mailto:funkyfly@gmx.net)

thanks for your help. thats a really cool community.

funkyfly

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 20, 2003, 7:28pm UTC](https://forum.kirupa.com/t/php-login-script-needed/23643/9 "2003-06-20T19:28:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 20, 2003, 8:23pm UTC](https://forum.kirupa.com/t/php-login-script-needed/23643/10 "2003-06-20T20:23:34Z")

</div>

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

take a look at [test link](http://www.vollhias.com/test)

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 21, 2003, 6:15am UTC](https://forum.kirupa.com/t/php-login-script-needed/23643/11 "2003-06-21T06:15:46Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 21, 2003, 9:50am UTC](https://forum.kirupa.com/t/php-login-script-needed/23643/12 "2003-06-21T09:50:19Z")

</div>

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 😉

funkyfly

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 21, 2003, 11:07am UTC](https://forum.kirupa.com/t/php-login-script-needed/23643/13 "2003-06-21T11:07:13Z")

</div>

You did fill in the html file right ?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 21, 2003, 11:14am UTC](https://forum.kirupa.com/t/php-login-script-needed/23643/14 "2003-06-21T11:14:29Z")

</div>

what you mean by that?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 21, 2003, 11:16am UTC](https://forum.kirupa.com/t/php-login-script-needed/23643/15 "2003-06-21T11:16:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 21, 2003, 11:21am UTC](https://forum.kirupa.com/t/php-login-script-needed/23643/16 "2003-06-21T11:21:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 21, 2003, 11:21am UTC](https://forum.kirupa.com/t/php-login-script-needed/23643/17 "2003-06-21T11:21:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 21, 2003, 11:26am UTC](https://forum.kirupa.com/t/php-login-script-needed/23643/18 "2003-06-21T11:26:05Z")

</div>

sure! you can find it [here](http://www.vollhias.com/test)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 21, 2003, 11:28am UTC](https://forum.kirupa.com/t/php-login-script-needed/23643/19 "2003-06-21T11:28:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 21, 2003, 11:29am UTC](https://forum.kirupa.com/t/php-login-script-needed/23643/20 "2003-06-21T11:29:13Z")

</div>

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

[Next page](https://forum.kirupa.com/t/php-login-script-needed/23643.md?page=2)
