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
 
Start new topic
Odpowiedzi
buliyo
post
Post #2





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

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


Cytat(kwiateusz @ 10.05.2009, 09:29:37 ) *
rozumiem że w skrypcie ktory kieruje do tego podanego wyżej ustawiasz $_SESSION['access'] na root?


jeszcze raz...
mam obecnie cos takiego:
index.php
  1. <?
  2. $_SESSION['access'] = 'root';
  3. ?>
  4. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  5. <html><head>
  6.  
  7. <TITLE>logowanie</TITLE>
  8. <META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=iso-8859-2">
  9. <link rel="stylesheet" type="text/css" href="styl.css">
  10. </HEAD>
  11. <BODY BGCOLOR="#434242">
  12. <FORM ACTION="login.php" METHOD="POST">
  13.  <CENTER><div class="moje">login:<BR>
  14.  <INPUT TYPE="TEXT" NAME="login" size=10><BR>
  15.  hasło:<BR>
  16.  <INPUT TYPE="PASSWORD" NAME="haslo" size=10><BR>
  17.  <INPUT TYPE="SUBMIT" name="submit" VALUE="Akceptuj"></div></CENTER>
  18.  </FORM>
  19.  
  20. </BODY>
  21. </HTML>

login.php
  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. }
  13.  if (isset($_POST['submit'])){
  14.  if (empty($_POST['login'])){
  15.      $message .= '<font class="blad">Nie podałeś loginu</font><br />';
  16.      $l = FALSE;}
  17.  else
  18.  {
  19.  $l = usun($_POST['login']);
  20.  }
  21.  if (empty($_POST['haslo']))
  22.  {
  23.  $message .= '<font class="blad">Nie podałeś hasła</font><br />';
  24.  $h = FALSE;
  25.  }
  26.  else
  27.  {
  28.  $h = usun($_POST['haslo']);
  29.  }
  30.  if ( $l && $h )
  31.  {
  32.  if($_POST['login'] == 'admin' && $_POST['haslo'] == 'admin')
  33.  {
  34.  $_SESSION['username'] = 'admin';
  35.  $_SESSION['access'] = 'admin';
  36.  $_GET['cmd'] = 'ok';
  37.  header ("Location: tabelki.php");  // przekierowuje nas na jaka strone chcemy
  38.  }
  39.  else
  40.  {
  41.  $message .= '<font class="blad">Błędne hasło lub login</font><br />';
  42.  }
  43.  }
  44.  else
  45.  {
  46.  $message .= '<font class="blad">Spróbuj jeszcze raz</font>';
  47.  }
  48. }
  49. ?>
  50. <div align="center">
  51. <? if(isset($message)){
  52. echo $message;
  53. }
  54. ?>
  55. </div>

tabelki.php
  1. <?
  2.  
  3. if($_SESSION['access'] != 'root'){
  4. @header ("Location:  index.php");
  5. }
  6. ?>
  7. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  8. <html><head>
  9.  
  10. <TITLE>tabelki</TITLE>
  11. <META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=iso-8859-2">
  12. <link rel="stylesheet" type="text/css" href="styl.css">
  13. </HEAD>
  14. <BODY BGCOLOR="#434242">
  15. działa!!
  16. </BODY>
  17. </HTML>

po logowaniu przy uzyciu admin/admin otrzymuje
Spróbuj jeszcze raz

(IMG:http://forum.php.pl/style_emoticons/default/sad.gif)
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: 9.10.2025 - 23:06