Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> problel z logowanie w sesji, skrypt gubi sesje
marcin547
post
Post #1





Grupa: Zarejestrowani
Postów: 11
Pomógł: 0
Dołączył: 23.11.2014

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


Witam tak jak w temacie loguje się za pomocą formularza jak poniżej, mam wrażenie że jak by było coś nie tak między $_SESSION['auth'] a zmienną $zalogowany chodzi o to że niby się loguje a po przejściu do dodawania formularza w drugiej zakładce to albo jestem ciągle zalogowany ale i tak nie mogę nic dodać albo nie widzę przycisku dodaj przetarg. Wcześniej to działało, nie działa po zmianie wersji php oraz w iis7 po dodaniu modułu url rewrite. skrypt jest nie mój i bazuje na link http://smarty.php.net/ @version 2.6.14

  1. <?php
  2.  
  3. if(count($bledy) > 0) {
  4. ?>
  5. <div style="margin:10px 0px;border:1px solid red;float:left;width:100%;text-align:center;">
  6. Błędnie podany login lub hasło.
  7. </div>
  8. <?php
  9. }
  10. if($_SESSION['auth'] === true) {
  11. ?>
  12. <div style="margin:10px 0px;float:left;width:100%;text-align:center;">
  13. Witaj <?php echo $_SESSION['login']; ?>.
  14. </div>
  15. <?php
  16. } else {
  17. ?>
  18.  
  19. <form action="" method="post" id="form_reg">
  20. <fieldset>
  21. <label for="login">
  22. <span class="label">
  23. Login:
  24. </span>
  25.  
  26. <input type="text" name="login" id="login" />
  27. </label>
  28. <label for="pass">
  29. <span class="label">
  30. Hasło:
  31. </span>
  32.  
  33. <input type="password" name="pass" id="pass" />
  34. </label>
  35. </fieldset>
  36. <div>
  37. <input type="submit" value="Loguj" name="submit_loguj" />
  38. </form>
  39.  
  40. <?php
  41. }
  42. ?>
  43. <?php
  44. if($_SESSION['auth'] === true) {
  45. ?>
  46. <div style="width:100%;text-align:center;margin:4px 0px;">
  47. <button onclick="location.href='/logout';return false;">Wyloguj</button>
  48. </div>
  49. <?php
  50. }
  51. ?>
  52.  
  53.  



po wykonaniu tego skryptu powinienem mieć możliwość dodawania przetargów :



  1.  
  2. {if $ok == 1}
  3. <div style="border:1px solid green;color:green;width:100%;text-align:center;padding:10px 0px;">Pomyślnie dodano przetarg</div>
  4. {/if}
  5. {if $did == 1}
  6. <div style="border:1px solid green;color:green;width:100%;text-align:center;padding:10px 0px;">Pomyślnie zdezaktywowano przetarg</div>
  7. {/if}
  8. {if $zalogowany === true}<button onclick="location.href='/dodaj/';return false;">Dodaj przetarg</button>{/if}
  9. <table>
  10. <tr style="font-weight:bold;text-align:center;">
  11. <td style="background-color:#d5d5d5;padding:3px;">
  12. <strong>Nr sprawy</strong>
  13. </td>
  14. <td style="background-color:#d5d5d5;padding:3px;">
  15. <strong>Przedmiot przetargu</strong>
  16. </td>
  17. {if $zalogowany === true}
  18. <td style="background-color:#d5d5d5;padding:3px;">
  19. </td>
  20. {/if}
  21. </tr>
  22. {foreach item=p from=$przetargi}
  23. <tr style="border:1px solid black;background-color:#{cycle values="f9f9f9,e7e7e7"};">
  24. <td onmouseover="this.style.textDecoration='underline'" onmouseout="this.style.textDecoration='none'" onclick="location.href='{$server_url}?id={$p.nr}';return false;" style="cursor:pointer;padding:2px;text-align:center;">
  25. {$p.nr_sprawy}
  26. </td>
  27. <td onmouseover="this.style.textDecoration='underline'" onmouseout="this.style.textDecoration='none'" onclick="location.href='{$server_url}?id={$p.nr}';return false;" style="cursor:pointer;padding:2px;">
  28. {$p.opis}
  29. </td>
  30. {if $zalogowany === true}
  31. <td>
  32. <button onclick="if(confirm('Czy jesteś pewien ?'))location.href='/przetargi/?did={$p.nr}';return false;">Usuń</button>
  33. </td>
  34. {/if}
  35. </tr>
  36. {/foreach}
  37. </table>
  38.  
  39.  
  40.  
  41.  





a tu przedstawiam klasy :


  1.  
  2. class User extends Base {
  3.  
  4. public $dane;
  5.  
  6. public function __construct() {
  7. parent::__construct();
  8. }
  9.  
  10. public function __destruct(){}
  11.  
  12. public function logowanie($login,$pass) {
  13. $conn = new Connection();
  14. if(($row = $conn->return_row('SELECT login FROM '.$this->_table_user.' WHERE aktywne = 1 AND login LIKE "'.$login.'" AND pass LIKE "'.md5($pass).'"')) !== false) {
  15. $this->setLogowanie($row);
  16. }
  17. }
  18.  
  19. private function setLogowanie($var) {
  20. $_SESSION['login'] = $var['login'];
  21. $_SESSION['auth'] = true;
  22. }
  23.  
  24. public function logout() {
  25. $_SESSION['login'] = '';
  26. $_SESSION['auth'] = false;
  27. unset($_SESSION);
  28. }
  29.  
  30. public function auth() {
  31. return (bool)$_SESSION['auth'];
  32. }
  33.  
  34. }
  35.  
  36. ?>
  37.  
  38.  
  39.  
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: 3.10.2025 - 20:34