Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]Błąd w $_SESSION['auth']
pawel06281990
post 8.02.2019, 20:57:09
Post #1





Grupa: Zarejestrowani
Postów: 281
Pomógł: 0
Dołączył: 10.01.2014

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


Witam,

Dostaje taki kod gdy minie czas sesji

  1. Notice: Undefined index: auth in /home/sfera/public_html/admin/administrator.php on line 6


I nie wiem co jest nie tak.

O to skrypt logowania.

  1. session_start();
  2. $_SESSION['auth'] = FALSE;
  3.  
  4. <?php
  5. /* jeżeli istnieje zmienna login oraz password i sesja z autoryzacją użytkownika jest FALSE to wykonaj
  6.   * skrypt logowania
  7.   */
  8. if (!isset($_POST['user_email']) && !isset($_POST['user_password']) && $_SESSION['auth']== FALSE) {
  9.  
  10. ?>
  11.  
  12. <div class="login-box">
  13.  
  14. <div class="login-logo">
  15. <a href="index"><img src="images/logo_zarzadzaj.png" alt="Panel Logowania - Zarządzanie cmentarzem" /></a>
  16. </div>
  17. <!-- /.login-logo -->
  18. <div class="login-box-body">
  19. <p class="login-box-msg"></p>
  20.  
  21. <form method="post">
  22. <div class="form-group has-feedback">
  23. <input type="text" class="form-control" name="user_email" placeholder="<?php echo $locale['global_101'];?>"><span class="glyphicon glyphicon-envelope form-control-feedback"></span>
  24. </div>
  25. <div class="form-group has-feedback">
  26. <input type="password" class="form-control" name="user_password" placeholder="<?php echo $locale['global_102'];?>"><span class="glyphicon glyphicon-lock form-control-feedback"></span>
  27. </div>
  28. <div class="row">
  29. <div class="col-xs-8">
  30. <div class="checkbox icheck">
  31. <select name="prawa" class="form-control">
  32. <option value="103"><?php echo $locale['user3'];?></option>
  33. <option value="102"><?php echo $locale['user2'];?></option>
  34. </select>
  35. </div>
  36. </div>
  37. <div class="col-xs-8">
  38. </div>
  39. <!-- /.col -->
  40. <div class="col-xs-4">
  41. <button type="submit" class="btn btn-primary btn-block btn-flat"><?php echo $locale['global_104'];?></button>
  42. </div>
  43. <!-- /.col -->
  44. </div>
  45. </form>
  46.  
  47.  
  48. <!-- /.social-auth-links -->
  49.  
  50. <?php echo $locale['global_105'];?><br>
  51. <?php echo $locale['global_106'];?>
  52.  
  53. </div>
  54. <!-- /.login-box-body -->
  55. </div>
  56. <?php
  57.  
  58.  
  59. }
  60.  
  61.  
  62. elseif (isset($_POST['user_email']) && isset($_POST['user_password']) && $_SESSION['auth'] == FALSE) {
  63.  
  64.  
  65. if (!empty($_POST['user_email']) && !empty($_POST['user_password'])) {
  66.  
  67.  
  68. $user_email = mysqli_real_escape_string($link,$_POST['user_email']);
  69. $user_password = mysqli_real_escape_string($link,$_POST['user_password']);
  70.  
  71.  
  72. $user_password =sha1($user_password);
  73.  
  74.  
  75. $sql = dbrows(dbquery($link,"SELECT * FROM ".$db_prefix."users WHERE user_email= '$user_email' AND user_password = '$user_password' AND user_level='".$_POST['prawa']."'"));
  76.  
  77.  
  78. if ($sql == 1) {
  79.  
  80.  
  81. $_SESSION['user'] = $user_email;
  82. $_SESSION['auth'] = TRUE;
  83.  
  84. $sql = dbquery($link,"UPDATE ".$db_prefix."users SET user_lastvisit='".time()."' , user_ip='".USER_IP."' WHERE user_email= '$user_email'");
  85.  
  86. echo'<div class="panel_logowania">';
  87. echo '<meta http-equiv="refresh" content="1; URL=panel">';
  88. echo '<p style="padding-top:8px";><h1><strong>Proszę czekać...</strong><br />trwa logowanie i wczytywanie danych</h1></p>
  89. </div>';
  90. }
  91.  
  92. else {
  93.  
  94. echo'<div class="panel_logowania">';
  95. echo '<p style="padding-top:10px;color:red";>Błęd podczas logowania do systemu<br />';
  96. echo '<a href="'.BASEDIR.'">Wróć do formularza</a></p>
  97. </div>';
  98. }
  99. }
  100.  
  101.  
  102. else {
  103.  
  104. echo'<div class="panel_logowania">';
  105. echo '<p style="padding-top:10px;color:red";>Błąd podczas logowania do systemu<br /> Sprawdz Login i hasło<br/>';
  106. echo '<a href="'.BASEDIR.'">Wróć do formularza</a></p>
  107. </div>';
  108. }
  109. }
  110.  
  111.  
  112. elseif ($_SESSION['auth'] == TRUE && !isset($_GET['logout'])) {
  113. echo'<div class="panel_logowania">';
  114. echo '<meta http-equiv="refresh" content="1; URL=panel">';
  115. echo '<p style="padding-top:10px"><strong>Proszę czekać...</strong><br />trwa wczytywanie danych</p>
  116. </div>';
  117. }
  118.  
  119.  
  120. elseif ($_SESSION['auth'] == TRUE && isset($_GET['logout'])) {
  121. $_SESSION['user'] = '';
  122. $_SESSION['auth'] = FALSE;
  123. echo'<div class="panel_logowania">';
  124. echo '<meta http-equiv="refresh" content="1; URL='.$_SERVER['HTTP_HOST'].'">';
  125. echo '<p style="padding-top:10px"><strong>Proszę czekać...</strong><br />trwa wylogowywanie</p>
  126. </div>';
  127. }
  128.  
  129. ?>
  130.  
  131.  


A tu skrypt który szyfruje dostęp do treści po zalogowaniu

  1. if ($_SESSION['auth'] == TRUE) {
  2. $user_email = $_SESSION['user'];
  3. $result = dbquery($link,"SELECT * FROM ".$db_prefix."users WHERE user_email='$user_email'")or die(mysql_error());
  4. $data = dbarray($result);
  5.  
  6.  
  7. //Treść zaszyfrowana
  8.  
  9.  
  10. }else{
  11. echo '<meta http-equiv="refresh" content="1; URL=index">';
  12. echo '<p style="padding-top:10px;color:black";><strong>Próba nieautoryzowanego dostępu...</strong><br />trwa przenoszenie do formularza logowania</p>';
  13. }


Ten błąd ukazuje się gdy przeszłem na mysqli . Proszę o pomoc bo już nie wiem co mam zrobić robiłem już wszystko.
Go to the top of the page
+Quote Post
Ruch Radzionków
post 10.02.2019, 22:38:25
Post #2





Grupa: Zarejestrowani
Postów: 311
Pomógł: 25
Dołączył: 29.08.2011

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


co znajduje się w tej linijce
Notice: Undefined index: auth in /home/sfera/public_html/admin/administrator.php on line 6


--------------------
Pomogłem daj pomógł
Go to the top of the page
+Quote Post
Pyton_000
post 11.02.2019, 08:26:54
Post #3





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

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


Kod PHP
  1. session_start();
  2. $_SESSION['auth'] = FALSE;
  3.  
  4. <?php
  5. /* jeżeli istnieje zmienna login oraz password i sesja z autoryzacją użytkownika jest FALSE to wykonaj
  6.   * skrypt logowania
  7.   */

wypadałoby wstawić ZA znacznik otwierający a nie przed wink.gif

Ten post edytował Pyton_000 11.02.2019, 08:27:23
Go to the top of the page
+Quote Post
pawel06281990
post 29.03.2019, 19:13:27
Post #4





Grupa: Zarejestrowani
Postów: 281
Pomógł: 0
Dołączył: 10.01.2014

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


Cytat(Ruch Radzionków @ 10.02.2019, 22:38:25 ) *


W tej linii znajduje się ten skrypt

  1. if ($_SESSION['auth'] = true) {
  2.  
  3. $user_email = $_SESSION['user'];
  4. $result = dbquery($link,"SELECT * FROM ".$db_prefix."users WHERE user_email='$user_email'")or die(mysqli_error());
  5. $data = dbarray($result);
  6. $result = dbquery($link,"SELECT * FROM ".$db_prefix."users WHERE user_id='".$data['user_id']."'");
  7. $userdata = dbarray ($result);
  8.  
  9. //strona szyfrowana
  10.  
  11. }else{
  12. echo '<meta http-equiv="refresh" content="1; URL=index">';
  13. echo '<p style="padding-top:10px;color:black";><strong>Próba nieautoryzowanego dostępu...</strong><br />trwa przenoszenie do formularza logowania</p>';
  14. }


Ten post edytował pawel06281990 29.03.2019, 19:13:58
Go to the top of the page
+Quote Post
Pyton_000
post 30.03.2019, 09:07:48
Post #5





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

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


No i co z tego? Zrobiłeś to co napisałem żebyś zrobił? Czy czytasz tylko to co chcesz?
Go to the top of the page
+Quote Post
pawel06281990
post 30.03.2019, 11:50:55
Post #6





Grupa: Zarejestrowani
Postów: 281
Pomógł: 0
Dołączył: 10.01.2014

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


Cytat(Pyton_000 @ 30.03.2019, 09:07:48 ) *
No i co z tego? Zrobiłeś to co napisałem żebyś zrobił? Czy czytasz tylko to co chcesz?


Zrobiłem tak jak mówiłeś i w czasie wylogowania powraca mi do strony szyfrowanej.

  1. $_SESSION['auth'] = FALSE;
  2. session_start();
  3. <?php
  4. /* jeżeli istnieje zmienna login oraz password i sesja z autoryzacją użytkownika jest FALSE to wykonaj
  5.   * skrypt logowania
  6.   */


Tak to zrobiłem
Go to the top of the page
+Quote Post
viking
post 30.03.2019, 11:52:35
Post #7





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

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


Czyli nic nie zrobiłeś. Dodatkowo

$_SESSION['auth'] === true) {


--------------------
Go to the top of the page
+Quote Post
pawel06281990
post 30.03.2019, 11:59:54
Post #8





Grupa: Zarejestrowani
Postów: 281
Pomógł: 0
Dołączył: 10.01.2014

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


Cytat(viking @ 30.03.2019, 11:52:35 ) *
Czyli nic nie zrobiłeś. Dodatkowo

$_SESSION['auth'] === true) {


Zrobiłem tak ja mi poradziliście
Go to the top of the page
+Quote Post
viking
post 30.03.2019, 12:16:11
Post #9





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

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


Cytat
wypadałoby wstawić ZA znacznik otwierający a nie przed wink.gif


  1. $_SESSION['auth'] = FALSE;
  2. session_start();
  3. <?php


No faktycznie. Tylko jakoś kod wygląda inaczej.

Ten post edytował viking 30.03.2019, 12:16:38


--------------------
Go to the top of the page
+Quote Post
pawel06281990
post 30.03.2019, 12:25:59
Post #10





Grupa: Zarejestrowani
Postów: 281
Pomógł: 0
Dołączył: 10.01.2014

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


No zmieniłem mu pozycję jak napisaliście
Go to the top of the page
+Quote Post
viking
post 30.03.2019, 12:36:23
Post #11





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

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


Bo warunek był zawsze spełniony tym ifem wyżej


--------------------
Go to the top of the page
+Quote Post
pawel06281990
post 23.04.2019, 18:33:43
Post #12





Grupa: Zarejestrowani
Postów: 281
Pomógł: 0
Dołączył: 10.01.2014

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


Wylogowało się z takimi błędami


Notice: Undefined index: auth in /home/sfera/public_html/admin/index.php on line 47

Notice: Undefined index: auth in /home/sfera/public_html/admin/index.php on line 51

to jest linia 47

  1. <?php
  2. /* jeżeli istnieje zmienna login oraz password i sesja z autoryzacją użytkownika jest FALSE to wykonaj
  3.   * skrypt logowania
  4.   */
  5. if (!isset($_POST['user_email']) && !isset($_POST['user_password']) && $_SESSION['auth']== FALSE) {
  6.  
  7. ?>


A to jest linia 51

  1. if ($_SESSION['auth'] == FALSE && isset($_GET['logout'])) {
  2. $_SESSION = array ();
  3.  
  4. echo"<div style='background: #CF9; border: 1px solid #060; width: 350px; margin: 5px; color: black; font-weight: bold; padding: 2px; text-align: center; margin-left: auto; margin-right: auto;'>Wylogowany Poprawnie</div>";
  5. }


I jaki jest w niosek questionmark.gif

Bo mój że nadal mu brakuje indeks: auth

chyba muszę zrobić coś takiego

$_SESSION['auth']=== FALSE

w if

OK poradziłem sobie wystarczyło zmienić w zaszyfrowanym pliku na

  1. if ($_SESSION['auth'] === TRUE) {
  2.  
  3.  
  4. }else {
  5.  
  6. echo '<meta http-equiv="refresh" content="1; URL=index">';
  7. echo '<p style="padding-top:10px;color:black;text-align: center; padding-top: 2em; margin-bottom: 4em;"><strong>Próba nieautoryzowanego dostępu...</strong><br />trwa przenoszenie do formularza logowania</p>';
  8.  
  9. }


I działa jak miało działać

Pozdrawiam

Ten post edytował pawel06281990 30.03.2019, 13:17:36
Go to the top of the page
+Quote Post

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

 



RSS Wersja Lo-Fi Aktualny czas: 28.03.2024 - 12:23