Inlog script vraag

Pagina: 1
Acties:

  • procyon
  • Registratie: Februari 2000
  • Laatst online: 12:10
Ik heb op het net een stukje code gevonden, het zou een stukje code zijn waarmee je sommige pagina's kan beveiligen met een wachtwoord..

Werken doet het alleen niet, is het wel compleet?
PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?
// if we are using IIS, we need to set $PHP_AUTH_USER and $PHP_AUTH_PW
if (substr($SERVER_SOFTWARE, 0, 9) == "Microsoft" &amp;&amp;
    !isset($PHP_AUTH_USER) &amp;&amp;
    !isset($PHP_AUTH_PW) &amp;&amp;
    substr($HTTP_AUTHORIZATION, 0, 6) == "Basic "
   )
{
  list($PHP_AUTH_USER, $PHP_AUTH_PW) =
    explode(":", base64_decode(substr($HTTP_AUTHORIZATION, 6)));
}

// Replace this if statement with a database query or similar
if ($PHP_AUTH_USER != "user" || $PHP_AUTH_PW != "pass")
{
  // visitor has not yet given details, or their
  // name and password combination are not correct

  header('WWW-Authenticate: Basic realm="Realm-Name"');
  if (substr($SERVER_SOFTWARE, 0, 9) == "Microsoft")
    header("Status: 401 Unauthorized");
  else
    header("HTTP/1.0 401 Unauthorized");

  echo "<h1>Go Away!</h1>";
  echo "You are not authorized to view this resource.";
}
else
{
  // visitor has provided correct details
  echo "<h1>Here it is!</h1>";
  echo "<p>I bet you are glad you you can see this secret page.";
}
?>

  • procyon
  • Registratie: Februari 2000
  • Laatst online: 12:10
of wordt er soms verwezen naar andere PHP scripts?

if ($PHP_AUTH_USER != "user" || $PHP_AUTH_PW != "pass")

  • ACM
  • Registratie: Januari 2000
  • Niet online

ACM

Software Architect

Werkt hier

Wat werkt er niet?
Wat geef je als invoer als het niet werkt?
Wat gebeurt er dan wel?

(voor es 'user' en 'pass' in bij het inlog scherm dat je moet krijgen)

  • procyon
  • Registratie: Februari 2000
  • Laatst online: 12:10
[b]
(voor es 'user' en 'pass' in bij het inlog scherm dat je moet krijgen)
Weet ik maar ik krijg geen inlog scherm..
dit krijg ik:
code:
1
2
3
4
5
6
7
8
Warning: Undefined variable: PHP_AUTH_USER in c:\program files\apache group\apache\htdocs\http.php on line 15

Warning: Cannot add header information - headers already sent by (output started at c:\program files\apache group\apache\htdocs\http.php:15) in c:\program files\apache group\apache\htdocs\http.php on line 20

Warning: Cannot add header information - headers already sent by (output started at c:\program files\apache group\apache\htdocs\http.php:15) in c:\program files\apache group\apache\htdocs\http.php on line 24

Go Away!
You are not authorized to view this resource

Verwijderd

Dit script is voor een IIS server (van MS) en jij gebruikt apache.
Kijk eens in de manual:
http://www.php.net/manual/en/features.http-auth.php
The HTTP Authentication hooks in PHP are only available when it is running as an Apache module and is hence not available in the CGI version.
Maar dat kun jij dus wel:
PHP:
1
2
3
4
5
6
7
8
9
10
11
<?
  if(!isset($PHP_AUTH_USER)) {
    header("WWW-Authenticate: Basic realm=\"My Realm\"");
    header("HTTP/1.0 401 Unauthorized");
    echo "Text to send if user hits Cancel button\n";
    exit;
  } else {
    echo "<p>Hello $PHP_AUTH_USER.</p>";
    echo "<p>You entered $PHP_AUTH_PW as your password.</p>";
  }
?>

  • LuCarD
  • Registratie: Januari 2000
  • Niet online

LuCarD

Certified BUFH

edit:

Het is vroeg, we gaan koffie halen

Programmer - an organism that turns coffee into software.


  • ACM
  • Registratie: Januari 2000
  • Niet online

ACM

Software Architect

Werkt hier

Kijk hier even naar: http://www.php.net/manual/en/features.http-auth.php

Jouw script ziet er een beetje gek uit, het voorbeeld van php is misschien wat duidelijker.

Dat werkte bij mij direct na copy&paste (een jaar geleden oid)

Verwijderd

ACM?
Lees jij mijn replies wel eens? :D ;)

  • ACM
  • Registratie: Januari 2000
  • Niet online

ACM

Software Architect

Werkt hier

Op dinsdag 25 september 2001 10:47 schreef daniel_hoenderdos het volgende:
ACM?
Lees jij mijn replies wel eens? :D ;)
Och, er zat wat tijd tussen het moment dat ik 'submit' en 'post reply' deed :)

Verwijderd

Drie minuten.
Figueres. :D

  • procyon
  • Registratie: Februari 2000
  • Laatst online: 12:10
Ik ben bang dat het dan aan mijn server ligt,
dit is nadat ik het voorbeeld stukje php code heb geprobeert.
code:
1
2
3
4
5
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, blabla@vlabla.nl and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

stukje uit het logbestand

[Tue Sep 25 10:59:56 2001] [error] [client 192.168.1.11] malformed header from script. Bad header=HTTP/1.0 401 Unauthorized: c:/php/php.exe

Verwijderd

Dat is dus deze header:
PHP:
1
2
3
<?
header("HTTP/1.0 401 Unauthorized");
?>

Gaan we weer naar de betreffende manual:
Note: Please be careful when coding the HTTP header lines. In order to guarantee maximum compatibility with all clients, the keyword "Basic" should be written with an uppercase "B", the realm string must be enclosed in double (not single) quotes, and exactly one space should precede the "401" code in the "HTTP/1.0 401" header line.
Of deze:
Configuration Note: PHP uses the presence of an AuthType directive to determine whether external authentication is in effect. Remember to avoid this directive for the context where you want to use PHP authentication (otherwise each authentication attempt will fail).
Ik vind overigens dat je nu zelf maar even alle comments ed in de manual moet lezen voor dat je weer met vragen komt.
Anders is het idd een misconfiguratie.

  • procyon
  • Registratie: Februari 2000
  • Laatst online: 12:10
Natuurlijk lees ik dat zelf ook, ik heb me aan alles gehouden toch?

Basic met hoofdletter, dubbele quotes, en precies een spatie in de "HTTP/1.0 401" header.

verder:
PHP uses the presence of an AuthType directive to determine whether external authentication is in effect. Remember to avoid this directive for the context where you want to use PHP authentication (otherwise each authentication attempt will fail).


Wat staat hier :?

Verwijderd

Wat denk je?
Je moet om die directive heen, anders gaat je poging tot php-auth naar de kloten.
Zal wel ergens in de conf files van je server zitten.
(Precies weet ik het ook niet trouwens)

  • procyon
  • Registratie: Februari 2000
  • Laatst online: 12:10
Wat denk je?
Je moet om die directive heen, anders gaat je poging tot php-auth naar de kloten.
Zal wel ergens in de conf files van je server zitten.
(Precies weet ik het ook niet trouwens)
Zover was ik ook, helaas doelde ik op een antwoord, het is nl zo dat ik ook niet precies weet hoe het zit..

Kan je wel boos roepen dat ik eens wat beter moet lezen maar als je het zelf ook niet weet, slaat dat dus nergens op

Verwijderd

Op dinsdag 25 september 2001 11:22 schreef daniel_hoenderdos het volgende:
Zal wel ergens in de conf files van je server zitten.
[aangepaste versie]
httpd.conf aanpassen ofzo?
Mazzel veel suc6
[/aangepaste versie]

  • procyon
  • Registratie: Februari 2000
  • Laatst online: 12:10
httpd.conf is het config bestand van de server ja....

ok opnieuw:

Er is waarschijnlijk iets mis met de config van mijn apache server, want als ik dit** script uitvoer krijg ik deze foutmelding:

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, blabla@vlabla.nl and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

** het stukje code:
PHP:
1
2
3
4
5
6
7
8
9
10
11
<?
  if(!isset($PHP_AUTH_USER)) {
    header("WWW-Authenticate: Basic realm=\"My Realm\"");
    header("HTTP/1.0 401 Unauthorized");
    echo "Text to send if user hits Cancel button\n";
    exit;
  } else {
    echo "<p>Hello $PHP_AUTH_USER.</p>";
    echo "<p>You entered $PHP_AUTH_PW as your password.</p>";
  }
?>

is het wel zo dat het aan mijn server ligt en zo ja, wat moet ik dan toevoegen aanpassen in het config bestand?

Verwijderd

Ik neem dus aan dat dit iets te maken heeft met die opmerking over de configuratie.
Dus 'iets' met die
AuthType directive to determine whether external authentication is in effect.
Wat weet je ook, namelijk dat je er omheen moet ofzoiets dergelijks.
Hoe weet ik dus niet, en ik weet natuurlijk ook niet hoe jou server inelkaar zit.
Dus raad ik je aan om de httpd.conf te openen en ff te zoeken op 'AuthType' (ctrl-f dus!) en zie eens wat dat opleverd.

  • procyon
  • Registratie: Februari 2000
  • Laatst online: 12:10
bedankt voor je reactie, maar er staat niets als AuthType in dat configbestand..

K*T man, dit..

Ik ga nu gewoon weer verder met de andere dingen, ben het ff zat.

  • MikeN
  • Registratie: April 2001
  • Laatst online: 19-09 19:19
Op dinsdag 25 september 2001 10:39 schreef Procyon for life het volgende:

[..]

Weet ik maar ik krijg geen inlog scherm..
dit krijg ik:
code:
1
2
3
4
5
6
7
8
Warning: Undefined variable: PHP_AUTH_USER in c:\program files\apache group\apache\htdocs\http.php on line 15

Warning: Cannot add header information - headers already sent by (output started at c:\program files\apache group\apache\htdocs\http.php:15) in c:\program files\apache group\apache\htdocs\http.php on line 20

Warning: Cannot add header information - headers already sent by (output started at c:\program files\apache group\apache\htdocs\http.php:15) in c:\program files\apache group\apache\htdocs\http.php on line 24

Go Away!
You are not authorized to view this resource
Zet in je php.ini is error_reporting op E_ALL & ~E_NOTICE
En probeer dan dat eerste script opnieuw... Dan zal hij niet de eerste foutmelding geven en moet de rest ook goed gaan.
Pagina: 1