Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP] Logowanie?
Homilian
post
Post #1





Grupa: Zarejestrowani
Postów: 6
Pomógł: 0
Dołączył: 28.02.2008

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


login.php
Kod
Kod jest nieaktualny! poniżej zamieszczam oba kody


Proszę o skorygowanie powyższego kodu (IMG:http://forum.php.pl/style_emoticons/default/smile.gif) , chciałem zrobić sesje z porównania danych wpisanych w pliku login.php i zawartych w pliku pass.php, domyślam się iż problem jest banalny jednak nie potrafię go sam rozwiązać..

Ten post edytował Homilian 21.06.2008, 14:39:28
Go to the top of the page
+Quote Post
webdice
post
Post #2


Developer


Grupa: Moderatorzy
Postów: 3 045
Pomógł: 290
Dołączył: 20.01.2007




session_start" title="Zobacz w manualu PHP" target="_manual na początku każdego pliku (o ile nie są one includowane) oraz wywal session_destroy" title="Zobacz w manualu PHP" target="_manual i drugie session_start" title="Zobacz w manualu PHP" target="_manual.
Go to the top of the page
+Quote Post
pyro
post
Post #3





Grupa: Zarejestrowani
Postów: 2 148
Pomógł: 230
Dołączył: 26.03.2008

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


po kiego po session_start dales od razu session_destroy ;p?
Go to the top of the page
+Quote Post
Homilian
post
Post #4





Grupa: Zarejestrowani
Postów: 6
Pomógł: 0
Dołączył: 28.02.2008

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


Niestety nie działa (IMG:http://forum.php.pl/style_emoticons/default/sad.gif)

admin.php
  1. <?php
  2.  
  3.  if (!isset($_SESSION['user'])) {
  4.  die('Nie jestes zalogowany.
  5.  Przekierowywanie do <a href="login.php">logowania...</a>
  6.  <meta http-equiv="refresh" content="2; url=login.php">');
  7.  }
  8.  
  9.  require_once ('config.php');
  10.  require_once ('pass.php');
  11.  include_once ('settings.php');
  12.  
  13.  echo('
  14.  <html>
  15.  <head>
  16.  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  17.  <meta http-equiv="content-language" content="pl" />
  18.  <meta http-equiv="Expires" content="0" />
  19.  <meta http-equiv="Cache-Control" content="no-store, no-cache, must-revalidate" />
  20.  <meta http-equiv="Cache-Control" content="post-check=0, pre-check=0" />
  21.  <meta http-equiv="Pragma" content="no-cache" />
  22.  <title>Panel administracyjny</title>
  23.  <link href="style.css" rel="stylesheet" type="text/css">
  24.  </head>
  25.  <body>
  26.  
  27.  
  28.  
  29.  <a href="admin.php">Jesteś zalogowany jako '.$_SESSION['user'].'</a><a href="login.php">Wyloguj</a>
  30.  
  31.  <a href="admin.php?e=1">Edytuj I</a><a href="admin.php?e=2">Edytuj II</a><a href="admin.php?e=3">Edytuj III</a><a href="admin.php?e=4">Edytuj IV</a>
  32.  ');
  33.  echo '</div><hr width="100%" size="1">';
  34.  
  35.  $db=mysql_connect ("$db_host", "$db_user", "$db_pass") or die ('ERROR: ' . mysql_error());
  36.  mysql_select_db ("$db_name") or die ('ERROR: ' . mysql_error());
  37.  echo ('<form name="form1" method="post" action="admin2.php"><textarea cols="115" rows="25">');
  38.  if($e=="1") {
  39.  echo ("$main1");
  40.  }
  41.  if($e=="2") {
  42.  echo ("$main2");
  43.  }
  44.  if($e=="3") {
  45.  echo ("$main3");
  46.  }
  47.  if($e=="4") {
  48.  echo ("$main4");
  49.  }
  50.  echo ('</textarea></form>');
  51.  ?>


login.php
  1. <?php
  2.  
  3.  
  4.  require_once ('config.php');
  5.  require_once ('pass.php');
  6.  include_once ('settings.php');
  7.  
  8.  $nick = $_POST['user'];
  9.  $hasl = $_POST['pass'];
  10.  
  11.  if($nick == $login{ 
  12.  
  13. if($hasl == $pass){
  14.  
  15. $_SESSION['user'] = $login;
  16. header("location:admin.php");
  17.  }
  18.  }
  19.  else {
  20.  
  21.  echo 'Zle haslo!';
  22.  
  23.  }
  24.  
  25.  echo('
  26.  <html>
  27.  <head>
  28.  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  29.  <meta http-equiv="content-language" content="pl" />
  30.  <title>Logowanie</title>
  31.  
  32.  </head>
  33.  <body>
  34.  <a href="index.php"><img src="universe.png" border="0"></a>
  35.  
  36.  
  37.  <h3>Logowanie</h3>
  38.  <hr width="100%" size="1">
  39.  <form id="form1" onsubmit="return check(this)" name="form1" method="post" action="'.$PHP_SELF.'">
  40.  <table>
  41.  <tr>
  42.  <td>Login </td>
  43.  <td><input name="user" type="text" id="user" /></td>
  44.  </tr>
  45.  <tr>
  46.  <td>Hasło </td>
  47.  <td><input name="pass" type="password" id="pass" /></td>
  48.  </tr>
  49.  </table>
  50.  
  51.  
  52.  <input name="login" type="submit" id="login" value="Zaloguj" />
  53.  </form>
  54.  </body>
  55.  </html>
  56.  ');
  57.  ?>
  58.  <script language=javascript>
  59.  <!--
  60.  function check(t){
  61. g = false;
  62. if(t.user.value.length==0){
  63. alert('Nie podałeś loginu');
  64. }
  65.  else if(t.pass.value.length==0){
  66. alert('Nie podałeś hasla');
  67.  else{
  68.  form1.submit();
  69.  g=true;
  70.  }
  71. return(g);
  72.  }
  73.  //-->
  74.  </script>

Mimo wszystko nie mogę zalogować się do Panelu Admina


@ EDIT: session_destroy miało niszczyć sesję po wylogowaniu się (IMG:http://forum.php.pl/style_emoticons/default/winksmiley.jpg) , logując się na nowo tworzysz nowa sesje (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)


Ten post edytował Homilian 21.06.2008, 14:52:03
Go to the top of the page
+Quote Post
.radex
post
Post #5





Grupa: Zarejestrowani
Postów: 1 657
Pomógł: 125
Dołączył: 29.04.2006

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


Nie działa po prostu, czy jakiś błąd wywala? Jeśli to drugie, to jaki błąd wywala?
Go to the top of the page
+Quote Post
Homilian
post
Post #6





Grupa: Zarejestrowani
Postów: 6
Pomógł: 0
Dołączył: 28.02.2008

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


Wcale nie wyświetla strony z logowaniem (IMG:http://forum.php.pl/style_emoticons/default/sad.gif)
Go to the top of the page
+Quote Post
erix
post
Post #7





Grupa: Moderatorzy
Postów: 15 467
Pomógł: 1451
Dołączył: 25.04.2005
Skąd: Szczebrzeszyn/Rzeszów




A daj var_dump" title="Zobacz w manualu PHP" target="_manual dla $_SESSION po session_start" title="Zobacz w manualu PHP" target="_manual i zobacz, co się tam dzieje.
Go to the top of the page
+Quote Post
Homilian
post
Post #8





Grupa: Zarejestrowani
Postów: 6
Pomógł: 0
Dołączył: 28.02.2008

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


Troszkę jaśniej?
Go to the top of the page
+Quote Post
Lejto
post
Post #9





Grupa: Zarejestrowani
Postów: 1 385
Pomógł: 48
Dołączył: 23.05.2007

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


sprawdź co zwróci var_dump(); np. var_dump($zmienna_sesji);
Go to the top of the page
+Quote Post
Homilian
post
Post #10





Grupa: Zarejestrowani
Postów: 6
Pomógł: 0
Dołączył: 28.02.2008

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


Zmienna var_dump zmienia nic nie zwraca bo nie może, wiedziałem iż problem jest banalny (IMG:http://forum.php.pl/style_emoticons/default/smile.gif) dzięki pomocy znajomego udało się naprawić problem ( login.php linijka 12 - niezamknięty nawias )
Go to the top of the page
+Quote Post
webdice
post
Post #11


Developer


Grupa: Moderatorzy
Postów: 3 045
Pomógł: 290
Dołączył: 20.01.2007




Tak na przyszłość, włącz sobie raportowanie o błędach.
Go to the top of the page
+Quote Post

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: 24.08.2025 - 05:18