Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Admin i użytkownik przy logowaniu
ReCiak
post
Post #1





Grupa: Zarejestrowani
Postów: 16
Pomógł: 0
Dołączył: 17.05.2019

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


Witam,mam problem mianowicie posiadam takie coś do logowania na stronę:
  1. if($_SESSION['zalogowany'] !== TRUE){
  2. include 'wyglad/index.html';
  3. odbierz_logowanie();
  4. }elseif($_SESSION['zalogowany'] === TRUE){
  5. echo 'Zostałeś poprawnie zalogowany.';
  6. }else{
  7. header('Location: /');
  8. }

a chciałbym żeby jedno konto np. admin było logowane z innego pliku jako administrator. Podpowie ktoś jak to zrobić? Jestem totalnie zielony w php mam projekt szkolny do zrobienia muszę to zrobić (IMG:style_emoticons/default/biggrin.gif) Z Góry dziękuje
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
miccom
post
Post #2





Grupa: Zarejestrowani
Postów: 493
Pomógł: 8
Dołączył: 7.07.2007
Skąd: Tychy

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


Cytat(dublinka @ 18.05.2019, 14:35:32 ) *
Popcorn biore.. (IMG:style_emoticons/default/smile.gif)

Ja jadłem popcorn jak Nospor tłumaczył Ci zasadę stronicowania (IMG:style_emoticons/default/smile.gif)

Do tego niezła komedia (IMG:style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post
dublinka
post
Post #3





Grupa: Zarejestrowani
Postów: 594
Pomógł: 66
Dołączył: 22.02.2008
Skąd: Dublin

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


Cytat(miccom @ 18.05.2019, 13:43:42 ) *
Ja jadłem popcorn jak Nospor tłumaczył Ci zasadę stronicowania (IMG:style_emoticons/default/smile.gif)

Do tego niezła komedia (IMG:style_emoticons/default/smile.gif)

Taaa ... Idz lepoiej dziecko poucz sie bo jutro klasówka (IMG:style_emoticons/default/biggrin.gif)

Nie wiem jaka masz strukture w bazie więc podam Ci przykład logowania dla wielu userów z wyk. tablicy pomocniczej.
Zamiast tego musisz pobrac sobie dane z bazy. 2 pliki z czego drugi nazywa sie 'gdziestam.php'

  1. <?php
  2.  
  3.  
  4. $AllDetails = array (
  5.  
  6. 'janek' => array('login' => 'janek', 'pass' => 'haslojanka'),
  7. 'franek' => array('login' => 'tomek', 'pass' => 'haslotomka'),
  8. 'admin' => array('login' => 'admin', 'pass' => 'hasloadmina')
  9.  
  10. );
  11.  
  12.  
  13.  
  14.  
  15.  
  16. if(!function_exists('LogIn'))
  17. {
  18.  
  19. function LogIn($ArgObj1)
  20. {
  21.  
  22. $ArgObj1 = "<form method=\"POST\" action=" . $_SERVER['SCRIPT_NAME'] . "?step=1>";
  23. $ArgObj1 .= "login: <input type=\"text\" name=\"LoginName\">";
  24. $ArgObj1 .= "Hasło: <input type=\"password\" name=\"PasswordName\">";
  25. $ArgObj1 .= "<input type=\"submit\" value=\"Loguj sie\" name=\"input\">";
  26. $ArgObj1 .= "</form>";
  27.  
  28. return $ArgObj1;
  29.  
  30. }
  31.  
  32. }
  33.  
  34. if(!function_exists('ShowLogOutLinkAndDetails'))
  35. {
  36.  
  37. function ShowLogOutLinkAndDetails($sess)
  38. {
  39.  
  40. return ($sess == 1) ? $sess . "<a href=" . $_SERVER['SCRIPT_NAME']. "?step=2>Wyloguj</a>" : $sess . "<a href=" . $_SERVER['SCRIPT_NAME']. "?step=2>Wyloguj</a>";
  41.  
  42. }
  43.  
  44. }
  45.  
  46.  
  47.  
  48. @$step = $_GET['step'];
  49.  
  50. (!isset($step)) ? $step = 0 : $step = $step;
  51.  
  52. switch($step):
  53.  
  54. case('0'):
  55.  
  56. if(isset($_SESSION['user']['login']))
  57. {
  58.  
  59. print ShowLogOutLinkAndDetails($_SESSION['user']['login']);
  60.  
  61.  
  62. } else {
  63.  
  64. echo LogIn($ArgObj1 = true);
  65.  
  66. }
  67.  
  68. break;
  69.  
  70. case('1'):
  71.  
  72. $submit = $_POST['input'];
  73. $LoginName = $_POST['LoginName'];
  74. $PasswordName = $_POST['PasswordName'];
  75.  
  76. if(isset($_SESSION['user']['login']))
  77. {
  78.  
  79. print ShowLogOutLinkAndDetails($_SESSION['user']['login']);
  80.  
  81.  
  82. } else {
  83.  
  84.  
  85. if($submit)
  86. {
  87. if( (trim($LoginName) != '') || (trim($PasswordName) != '') )
  88. {
  89.  
  90. if(isset($AllDetails[$LoginName]['login']) && isset($AllDetails[$LoginName]['pass']))
  91. {
  92. if( ($AllDetails[$LoginName]['login'] == $LoginName ) && ($AllDetails[$LoginName]['pass'] == $PasswordName) )
  93. {
  94.  
  95. if ($_SERVER['REQUEST_METHOD'] === 'POST')
  96. {
  97.  
  98.  
  99. if(session_status() == PHP_SESSION_ACTIVE)
  100. {
  101.  
  102.  
  103.  
  104. if($AllDetails[$LoginForm]['login'] == 'admin')
  105. {
  106.  
  107. $_SESSION['user']['login'] = $AllDetails[$LoginName]['login'];
  108.  
  109.  
  110. header('location: gdziestam.php');
  111.  
  112. } else
  113. {
  114.  
  115. $_SESSION['user']['login'] = $AllDetails[$LoginName]['login'];
  116.  
  117.  
  118. header('location: gdziestam.php');
  119.  
  120. }
  121.  
  122.  
  123.  
  124. } else {
  125.  
  126. header('location:' . $_SERVER['SCRIPT_NAME']);
  127.  
  128. }
  129.  
  130.  
  131. }
  132.  
  133.  
  134. } else {
  135.  
  136. exit("Dane są nieprawidłowe <a href=". $_SERVER['SCRIPT_NAME'] .">WSTECZ</a>");
  137. }
  138. } else {
  139. header('location:' . $_SERVER['SCRIPT_NAME']);
  140. }
  141. }else {
  142.  
  143. exit('Prosze wypelnic pola');
  144.  
  145. }
  146. } else {
  147.  
  148. exit("błąd");
  149.  
  150. }
  151. }
  152.  
  153. break;
  154.  
  155. case('2'):
  156.  
  157. unset($_SESSION['user']['login']);
  158.  
  159.  
  160. $_SESSION = array();
  161.  
  162. if (ini_get("session.use_cookies"))
  163. {
  164. setcookie(session_name(), '', time() - 3600,
  165. $params["path"], $params["domain"],
  166. $params["secure"], $params["httponly"]);
  167. }
  168.  
  169. header('location:' . $_SERVER['SCRIPT_NAME']);
  170.  
  171. break;
  172.  
  173. default:
  174. header('location:' . $_SERVER['SCRIPT_NAME']);
  175.  
  176.  
  177. endswitch;
  178.  
  179. ?>


gdziestam.php

  1. <?php
  2.  
  3.  
  4. if($_SESSION['user']['login'] == 'user')
  5. {
  6. print 'zawartosc strony dla uzytkownika';
  7. print " <a href=index.php?step=2>Wyloguj</a>";
  8. }
  9. if($_SESSION['user']['login'] == 'admin')
  10. {
  11. print 'zawartosc strony dla admina';
  12. print " <a href=index.php?step=2>Wyloguj</a>";
  13. }
  14.  
  15. ?>


Ten post edytował dublinka 19.05.2019, 08:52:17
Go to the top of the page
+Quote Post

Posty w temacie


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 Aktualny czas: 12.10.2025 - 13:32