Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Przerobienie logowania
buliyo
post
Post #1





Grupa: Zarejestrowani
Postów: 82
Pomógł: 0
Dołączył: 9.01.2006

Ostrzeżenie: (0%)
-----


Witam znalazłem kiedyś na tym forum taki zgrabny skrypcik do logowania sie na sesjach z userem w mysql..
  1. <?
  2. require_once('./config.php');
  3. if($_SESSION['access'] != 'root'){
  4. @header ("Location:  index.php");
  5. }
  6. function usun($data)
  7. {
  8. GLOBAL $dbc;
  9.  if (ini_get('magic_quotes_gpc'))
  10.  {
  11.      $data = stripslashes($data);
  12.  }
  13. return mysql_real_escape_string($data, $dbc);
  14. }
  15.  if (isset($_POST['submit'])){
  16.  if (empty($_POST['login'])){
  17.      $message .= '<font class="blad">Nie podałeś loginu</font><br />';
  18.      $l = FALSE;}
  19.  else
  20.  {
  21.  $l = usun($_POST['login']);
  22.  }
  23.  if (empty($_POST['haslo']))
  24.  {
  25.  $message .= '<font class="blad">Nie podałeś hasła</font><br />';
  26.  $h = FALSE;
  27.  }
  28.  else
  29.  {
  30.  $h = usun($_POST['haslo']);
  31.  }
  32.  if ( $l && $h )
  33.  {
  34.  $query = "SELECT username, access FROM user WHERE username='$l' AND haslo=password('$h')";
  35.  $result = mysql_query($query);
  36.  $row = mysql_fetch_array ($result, MYSQL_ASSOC);
  37.  if($row)
  38.  {
  39.  $_SESSION['username'] = $row['username'];
  40.  $_SESSION['access'] = $row['access'];
  41.  $_GET['cmd'] = 'ok';
  42.  header ("Location: list.php");  // przekierowuje nas na jaka strone chcemy
  43.  }
  44.  else
  45.  {
  46.  $message .= '<font class="blad">Błędne hasło lub login</font><br />';
  47.  }
  48.  }
  49.  else
  50.  {
  51.  $message .= '<font class="blad">Spróbuj jeszcze raz</font>';
  52.  }
  53. }
  54. ?>
  55. <div align="center">
  56. <? if(isset($message)){
  57. echo $message;
  58. }
  59. ?>
  60. </div>


chciałem go przerobić aby user i haslo bylo na sztywno w kodzie, zrobilem cos takiego:
  1. <?
  2. if($_SESSION['access'] != 'root'){
  3. @header ("Location:  index.php");
  4. }
  5. function usun($data)
  6. {
  7. GLOBAL $dbc;
  8.  if (ini_get('magic_quotes_gpc'))
  9.  {
  10.      $data = stripslashes($data);
  11.  }
  12. return mysql_real_escape_string($data, $dbc);
  13. }
  14.  if (isset($_POST['submit'])){
  15.  if (empty($_POST['login'])){
  16.      $message .= '<font class="blad">Nie podałeś loginu</font><br />';
  17.      $l = FALSE;}
  18.  else
  19.  {
  20.  $l = usun($_POST['login']);
  21.  }
  22.  if (empty($_POST['haslo']))
  23.  {
  24.  $message .= '<font class="blad">Nie podałeś hasła</font><br />';
  25.  $h = FALSE;
  26.  }
  27.  else
  28.  {
  29.  $h = usun($_POST['haslo']);
  30.  }
  31.  {
  32.  $_SESSION['username'] = 'admin';
  33.  $_SESSION['access'] = 'admin';
  34.  $_GET['cmd'] = 'ok';
  35.  header ("Location: tabelki.php");  // przekierowuje nas na jaka strone chcemy
  36.  }
  37.  else
  38.  {
  39.  $message .= '<font class="blad">Błędne hasło lub login</font><br />';
  40.  }
  41.  }
  42.  else
  43.  {
  44.  $message .= '<font class="blad">Spróbuj jeszcze raz</font>';
  45.  }
  46. }
  47. ?>
  48. <div align="center">
  49. <? if(isset($message)){
  50. echo $message;
  51. }
  52. ?>
  53. </div>

ale niestety wywala

Parse error: syntax error, unexpected T_ELSE in /login.php on line 42

czy ogolnie moj zamysl jest dobry tylko mam gdzies blad ze skladnia?
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 17.09.2025 - 18:02