PHP Authentication, wat is hier fout?

Pagina: 1
Acties:
  • 63 views sinds 30-01-2008

  • Gosu
  • Registratie: December 2001
  • Laatst online: 24-06-2022

Gosu

UltraBook

Topicstarter
Krijg telkens autho opnieuw en kom er niet in...

code:
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php 

$auth = false; // Assume user is not authenticated 

if (isset( $PHP_AUTH_USER ) && isset($PHP_AUTH_PW)) { 

mysql_connect("localhost","user");
mysql_select_db("db");

    // Formulate the query 

    $sql = "SELECT * FROM users WHERE 
            name = '$PHP_AUTH_USER' AND 
            password = '$PHP_AUTH_PW'"; 

    // Execute the query and put results in $result 

    $result = mysql_query( $sql ) 
        or die ( 'Unable to execute query.' ); 

    // Get number of rows in $result. 

    $num = mysql_numrows( $result ); 

    if ( $num != 0 ) { 

        // A matching row was found - the user is authenticated. 

        $auth = true;


    } 

} 

if ( ! $auth ) { 

    header( 'WWW-Authenticate: Basic realm="Private"' ); 
    header( 'HTTP/1.0 401 Unauthorized' ); 
    echo 'Authorization Required.'; 
    exit; 

} else { 

    echo '<P>You are authorized!</P>'; 
} 

?>

Del XPS 13


  • Tom-my
  • Registratie: November 2000
  • Laatst online: 21-05-2025

Tom-my

w03iz0rz

zet is echo's hier en daar tussen, kijko f je variabelen een waarde hebben?

basic stuf m8, en als jij die code zelf gemaakt hebt moet je daar echt wel uit kunnen komen.

"Then there was the man who drowned crossing a stream with an average depth of six inches."


  • PowerSp00n
  • Registratie: Februari 2002
  • Laatst online: 20-05 23:44

PowerSp00n

There is no spoon

euhm?
PHP Version Note: Autoglobals, such as $_SERVER, became available in PHP version 4.1.0. $HTTP_SERVER_VARS has been available since PHP 3.
?

  • Gosu
  • Registratie: December 2001
  • Laatst online: 24-06-2022

Gosu

UltraBook

Topicstarter
Kan nix tonen ;)

Zelfs simpel dingie als dit:
code:
1
2
3
4
5
6
7
8
9
10
11
<?php
  if(!isset($PHP_AUTH_USER)) {
    Header("WWW-Authenticate: Basic realm=\"Mijn Realm\"");
    Header("HTTP/1.0 401 Unauthorized");
    echo "Tekst om te sturen als de gebruiker op Annuleren klikt.\n";
    exit;
  } else {
    echo "Hallo $PHP_AUTH_USER.<P>";
    echo "Je gebruikte $PHP_AUTH_PW als je password.<P>";
  }
?>

werkt niet...

3 times proberen en dan :

"Tekst om te sturen als de gebruiker op Annuleren klikt."

Del XPS 13


  • Gosu
  • Registratie: December 2001
  • Laatst online: 24-06-2022

Gosu

UltraBook

Topicstarter
et is meer in fout in apache... maar wat :S bij anderen werkt dit prima

http://docter.student.utwente.nl/blabla.php

code:
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>";  
  }  
?>


bij mij niet

http://130.89.200.183:8080/inlog.php

[ Voor 17% gewijzigd door Gosu op 09-12-2003 01:27 ]

Del XPS 13


Verwijderd

versie PHP even controleren?

  • drm
  • Registratie: Februari 2001
  • Laatst online: 09-06-2025

drm

f0pc0dert

Gosu:
et is meer in fout in apache... maar wat :S bij anderen werkt dit prima
Joehoe :w, luister je wel, of doe jij topics graag in een soort van monoloog :?

Kijk nou nog eens naar wat PowerSp00n zegt en vervolgens even in de FAQ en laat dan even weten of het geholpen heeft :z

Music is the pleasure the human mind experiences from counting without being aware that it is counting
~ Gottfried Leibniz


  • curry684
  • Registratie: Juni 2000
  • Laatst online: 12-05 22:23

curry684

left part of the evil twins

En naast dat dit basic is is het ook nog een waardeloos 'hier-is-mijn-code-en-hij-doetutnie' topic zonder eigen inzet of voorwerk. We willen je best helpen bij een probleem, nadat je zelf hebt gedebugged. Dus lees die posts van PowerSp00n en drm nog eens en steek er de volgende keer aub iets meer moeite in: we hebben niet voor niet zo'n gave quickstart geschreven.

Professionele website nodig?

Pagina: 1

Dit topic is gesloten.