| | | | |
| |||||||
| PHP-Fortgeschrittene Arbeiten mit PHP ohne Einschränkungen |
|
| | LinkBack | Themen-Optionen | Thema bewerten |
| | |
| Gast
Beiträge: n/a
| hallo leute, bitte ich brauche eure hilfe. ich hab von einem php-buch das login script mit sessions und mysql übernommen. das funktioniert soweit auch ganz gut, nur wenn ich jetzt meine dateien mit einem script vor unbefugtem aufruf schützen möchte erhalte ich immer folgende fehlermeldung. Warning: Cannot add header information - headers already sent by (output started at d:\home\www\xyz.net\tool_fertig_fragen\index.php:2 5) in d:\home\www\xyz.net\tool_fertig_fragen\autorisieru ngs_pruefung.php on line 31 ich stell hier mal den ganzen quelltext dazu her, leider ist er etwas länger, aber so kann sich jeder gleich ein bild machen. bitte helft mir weiter. vorab schon danke index.php <?php // // Function that returns the HTML FORM that is // used to collect the user-name and password // function login_page($errorMessage) { // Generate the Login-in page ?> <?php include('start.php'); ?> <? } // // Function that returns HTML page showing that // the user with the $currentLoginName is logged on // function logged_on_page($currentLoginName) { // Generate the page that shows the user // is already authenticated and authorized ?> <?php include('start_ok.php'); ?> <? } // Main session_start(); // Check if we have established a session if (isset($HTTP_SESSION_VARS["authenticatedUser"])) { // There is a user logged on logged_on_page( $HTTP_SESSION_VARS["authenticatedUser"]); } else { // No session established, no POST variables // display the login form + any error message login_page($HTTP_SESSION_VARS["loginMessage"]); session_destroy(); } ?> start.php <html> <head> <title>Thetool</title> <link href="stylees.css" rel="stylesheet" type="text/css"> </head> <body> <div style="position:absolute; top:0px; left:0px;"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td colspan="2"><?php include('header.php'); ?></td> </tr> <tr> <td width="15%" style="border-right: 3px solid #CC9933; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px;" valign="top" bgcolor="#000066"> <form method="POST" action="authentifizierungsscript.php"> <? // Include the formatted error message if (isset($errorMessage)) echo "<font color=red>$errorMessage</font>"; // Generate the login <form> layout ?> <table> <tr> <td class="LinkeNavigationWeiss">Benutzer:</td> <td><input type="text" size=10 maxlength=20 name="formUsername"> </td> </tr> <tr> <td class="LinkeNavigationWeiss">Passwort:</td> <td><input type="password" size=10 maxlength=20 name="formPassword"> </td> </tr> </table> <div align="right"> <input type="submit" class="LinkeNavigationSchwarz" value="Anmelden"> </div> </form> </td> <td width="85%" bgcolor="#CCCCCC">Mainteil</td> </tr> </table> </div> </body> </html> authentifizierungsscript.php <?php include 'db.inc'; include 'error.inc'; function authenticateUser($connection, $username, $password) { // Test that the username and password // are both set and return false if not if (!isset($username) || !isset($password)) return false; // Get the two character salt from the username $salt = substr($username, 0, 2); // Encrypt the password $crypted_password = crypt($password, $salt); // Formulate the SQL query find the user $query = "SELECT password FROM users WHERE user_name = '$username' AND password = '$crypted_password'"; // Execute the query $result = @ mysql_query ($query, $connection) or showerror(); // exactly one row? then we have found the user if (mysql_num_rows($result) != 1) return false; else return true; } // Main ---------- session_start(); $authenticated = false; // Clean the data collected from the user $appUsername = clean($HTTP_POST_VARS["formUsername"], 10); $appPassword = clean($HTTP_POST_VARS["formPassword"], 15); // Connect to the MySQL server $connection = @ mysql_connect($hostName, $username, $password) or die("Keine Verbindung zur MySQL-Datenbank"); if (!mysql_selectdb($databaseName, $connection)) showerror(); $authenticated = authenticateUser($connection, $appUsername, $appPassword); if ($authenticated == true) { // Register the customer id session_register("authenticatedUser"); $authenticatedUser = $appUsername; // Register the remote IP address session_register("loginIpAddress"); $loginIpAddress = $REMOTE_ADDR; } else { // The authentication failed session_register("loginMessage"); $loginMessage = "Für den Benutzer \"$appUsername\" konnte keine Verbindung zur Datenbank hergestellt werden."; } // Relocate back to the login page header("Location: index.php"); ?> start_ok.php <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" > <html> <head> <title>Thetool</title> <link href="stylees.css" rel="stylesheet" type="text/css"> </head> <body> <div style="position:absolute; top:0px; left:0px;"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td colspan="2"><?php include('header.php'); ?></td> </tr> <tr> <td width="15%" style="border-right: 3px solid #CC9933; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px;" valign="top" bgcolor="#000066"> <table> <tr> <td> <?=$currentLoginName ?> abmelden </td> </tr> </table> </td> <td width="85%" bgcolor="#CCCCCC">Mainteil <?php include ('navigation.php');?></td>passiert der fehler ? </tr> </table> </div> </body> </html> logout.php <?php session_start(); $appUsername = $HTTP_SESSION_VARS["authenticatedUser"]; $loginMessage = "Benutzer \"$appUsername\" abgemeldet"; session_register("loginMessage"); session_unregister("authenticatedUser"); // Relocate back to the login page header("Location: index.php"); ?> autorisierungs_pruefung.php <?php session_start(); $loginScript = "index.php"; // Set a boolean flag to check if // a user has authenticated $notAuthenticated = !isset($HTTP_SESSION_VARS["authenticatedUser"]); // Set a boolean flag to true if this request // originated from the same IP address // as the one that created this session $notLoginIp = isset($HTTP_SESSION_VARS["loginIpAddress"]) && ($HTTP_SESSION_VARS["loginIpAddress"] != $REMOTE_ADDR); // Check that the two flags are false if($notAuthenticated) { // The request does not identify a session session_register("loginMessage"); $jerrynotAuthenticated = "passiert"; $loginMessage = "Sie sind nicht berechtigt die " . "URL $REQUEST_URI aufzurufen."; // Re-locate back to the Login page header("Location: " . $loginScript); exit; } else if($notLoginIp) { // The request did not originate from the machine // that was used to create the session. // THIS IS POSSIBLY A SESSION HIJACK ATTEMPT session_register("loginMessage"); $jerrynotLoginIp = "passiert"; $loginMessage = "Sie sind nicht berechtigt die " . "URL $REQUEST_URI von der Adresse $REMOTE_ADDR aufzurufen"; // Re-locate back to the Login page header("Location: " . $loginScript); exit; } // Ausgaben die nur zum testen ist print "loginscript=".$loginScript;?> <?php print "notAuthenticated=".$notAuthenticated;?> <?php print "notLoginIp=".$notLoginIp;?> <?php $Authenticated = $HTTP_SESSION_VARS["authenticatedUser"]; print "Authenticated=".$Authenticated;?> <?php $sessionvars = $HTTP_SESSION_VARS["loginIpAddress"];?> <?php print "sessionvars=".$sessionvars;?> <?php print "jerrynotAuthenticated=".$jerrynotAuthenticate d;?> <?php print "jerrynotLoginIp=".$jerrynotLoginIp;?> <?php ?> navigation.php <?php include ('autorisierungs_pruefung.php'); ?> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td>Zeile 1</td> </tr> </table> db.inc <?php $hostName = "localhost"; $databaseName = "thetool"; $username = "benutzer"; $password = "passwort"; function clean($input, $maxlength) { $input = substr($input, 0, $maxlength); $input = EscapeShellCmd($input); return ($input); } ?> eroor.inc <? function showerror() { die("Error " . mysql_errno() . " : " . mysql_error()); } ?> header.php <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="411" style="border-bottom: 3px solid #CC9933;" rowspan="2">[img]images/simskultur_akquisition_head.gif[/img]</td> <td width="%" bgcolor="6699FF"></td> </tr> <tr> <td width="%" style="border-bottom: 3px solid #CC9933; padding-bottom: 10px;" valign="bottom" bgcolor="6699FF"> <div align="right"> <? $wochentag=array("Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag");// Wochentage $monat=array("January"=>"Januar", "February"=>"Februar", "March"=>"März", "April"=>"April", "May"=>"Mai", "June"=>"Juni", "July"=>"Juli", "August"=>"August", "September"=>"September", "October"=>"Oktober", "November"=>"November", "December"=>"Dezember");// Monatsnamen echo $wochentag[date("w")] . ", " . date("d. ") . $monat[date("F")]. " " . date("Y") . ", " . date("H:i") . " Uhr"; ?> </div> </td> </tr> </table> |
|
| | |
| PHP Code Flüsterer Registriert seit: 21.08.2005 Beiträge: 4682 PHP-Kenntnisse: Fortgeschritten | |
| | |
| Erfahrener Benutzer Registriert seit: 08.06.2004
Beiträge: 865
![]() | Die Fehlermeldung heißt, dass du auf Zeile 25 eine Ausgabe machst, diese darf aber nicht vor header(), session_start() oder setcookie() auftreten. Um die Ausgabe zu verhindern, kannst du ob_start() bzw. um sie dann zu starten ob_end_flush() verwenden. Du solltest aber die Code oder PHP-Tags benutzen, um deinen Code etwas übersichtlicher darzustellen. mfg RudiS
__________________ Kunst kommt von Können und nicht von wollen, denn sonst würde es ja Wunst heißen. |
| | |
|
| Themen-Optionen | |
| Thema bewerten | |
|
|
Ähnliche Themen | ||||
| Thema | Autor | Forum | Antworten | Letzter Beitrag |
| Forum Login per curl | leb0rtran | PHP Tipps 2008 | 1 | 19.03.2008 12:47 |
| Login per Session oder htaccess? | FI-DD | PHP Tipps 2008 | 9 | 31.01.2008 21:19 |
| Login, Session und der ganze Rest | nikosch | PHP Tipps 2007 | 10 | 25.03.2007 05:48 |
| Etwas komplexerer Login --> Keine Angst, Suche benutzt | dethlef14 | PHP Tipps 2006 | 7 | 02.10.2006 00:35 |
| [Erledigt] Benutzername nach Login noch benötigt- Cookie oder Session? | PHP Tipps 2005-2 | 1 | 30.10.2005 09:20 | |
| [Erledigt] php session problem :( | PHP Tipps 2005-2 | 5 | 21.10.2005 16:37 | |
| Nach Einfügugng der Sessions funktioniert mein Program nicht | PHP-Fortgeschrittene | 1 | 02.10.2005 06:13 | |
| Session funktioniert nicht | PHP-Fortgeschrittene | 5 | 21.09.2005 16:23 | |
| Bei Session - verfall | socke | PHP Tipps 2005-2 | 12 | 01.09.2005 02:30 |
| Session Login | LA-Finest | PHP Tipps 2005-2 | 4 | 05.07.2005 10:46 |
| [Erledigt] Hilfe...PhpBB Session Problem!! | PHP Tipps 2004-2 | 2 | 15.12.2004 18:28 | |
| Session Problem beim Login | PHP Tipps 2004-2 | 6 | 15.12.2004 09:37 | |
| Login funktioniert mit MD5 nicht | PHP Tipps 2004-2 | 8 | 13.12.2004 19:32 | |
| login mit session geht ne | PHP Tipps 2004-2 | 4 | 08.12.2004 15:48 | |
| Session funktioniert nicht | PHP Tipps 2004 | 3 | 15.08.2004 13:08 | |

Dieser Inhalt ist unter einer Creative Commons-Lizenz lizenziert.