Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [php] Zablokowanie podstrony " strona dostępna po zalogowaniu, Jak zablokować stronę,aby była dostępna po zalogowaniu ?
kiepski96
post 10.12.2010, 20:19:32
Post #1





Grupa: Zarejestrowani
Postów: 233
Pomógł: 0
Dołączył: 22.02.2010

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


Chciałbym zabezpieczyć wszystkie podstrony mojej strony,oprócz rejestracji,aby były dostępne wyłącznie po zalogowaniu.
Jeśli się ktoś nie zaloguje i np. wpisze w przeglądarkę:

www.aaa.pl/podstrona1.html to aby przekierowało go na logowanie.


Jaki dać kod do podstron ?


Proszę o szybką odpowiedź.
Powód edycji: [strife]: Dodałem tag
Go to the top of the page
+Quote Post
lord2105
post 10.12.2010, 20:28:01
Post #2





Grupa: Zarejestrowani
Postów: 380
Pomógł: 59
Dołączył: 24.04.2010
Skąd: London

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


Po 1 nie ten dzial - Przedszkole

Nie moga byc to pliki html tylko php

dodajesz do kazdego pliku:

  1. if ($_SESSION['zalogowany']) {
  2. //tresc kodu
  3. }
  4. else {
  5. header('Location: login.php');
  6. }


podczas logowania sprawdzasz czy dany user jest w bazie, pliku txt i ustawiasz sesje 'zalogowany' na 1


--------------------
40% rozwiązań znajduje się tutaj.
59,9% tutaj.

Jeśli pomogłem rozwiązać Twój problem wciśnij
Go to the top of the page
+Quote Post
kiepski96
post 11.12.2010, 10:23:40
Post #3





Grupa: Zarejestrowani
Postów: 233
Pomógł: 0
Dołączył: 22.02.2010

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


Zrobiłem taki kod pliku aaa.php

Z poprawnego zalogowania jest przekierowanie właśnie na aaa.php.

Dodam,że w indexie jest pane logowania
Ale jest jakiś błąd,bo po zalogowaniu od razu wywala do indexu,cały czas blokuje,nawet jeśli jest się zalogowanym.Jaki jest błąd?


  1. <?php
  2. if(empty($_SESSION['username']))
  3. {
  4. header('Location: index.php');
  5. }
  6. else
  7. {
  8. ?>
  9. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  10. <html>
  11. <head>
  12. <meta http-equiv="Content-Language" content="pl">
  13. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  14. <title>Kategorie</title>
  15. <meta name="description" content="bcg">
  16. <meta name="keywords" content="dfh bd">
  17. <meta name="author" content="vvsxv">
  18. <meta name="categories" content="bcxb">
  19. <meta name="generator" content="gcxb ">
  20. <link rel="shortcut icon" href="favicon.ico">
  21. <style type="text/css">
  22. body
  23. {
  24. background-color: #000000;
  25. color: #000000;
  26. }
  27. </style>
  28. </head>
  29. <body>
  30. <div id="wb_Shape1" style="margin:0;padding:0;position:absolute;left:0px;top:100px;width:1277px;height
    :40px;text-align:center;z-index:0;">
  31. <img src="images/img0006.png" id="Shape1" alt="" title="" style="border-width:0;width:1277px;height:40px"></div>
  32. <div id="wb_Image1" style="margin:0;padding:0;position:absolute;left:0px;top:0px;width:200px;height:10
    0px;text-align:left;z-index:1;">
  33. <img src="images/logo.png" id="Image1" alt="" border="0" style="width:200px;height:100px;"></div>
  34. <div id="wb_Shape2" style="margin:0;padding:0;position:absolute;left:51px;top:105px;width:81px;height:
    28px;text-align:center;z-index:2;">
  35. <a href="./index.php"><img src="images/img0007.png" id="Shape2" alt="" title="" style="border-width:0;width:81px;height:28px"></a></div>
  36. <div id="wb_Shape3" style="margin:0;padding:0;position:absolute;left:149px;top:105px;width:81px;height
    :28px;text-align:center;z-index:3;">
  37. <a href="./Kategorie.php"><img src="images/img0008.png" id="Shape3" alt="" title="" style="border-width:0;width:81px;height:28px"></a></div>
  38. <div id="wb_Shape4" style="margin:0;padding:0;position:absolute;left:247px;top:105px;width:81px;height
    :28px;text-align:center;z-index:4;">
  39. <a href="./pomoc.php"><img src="images/img0009.png" id="Shape4" alt="" title="" style="border-width:0;width:81px;height:28px"></a></div>
  40. <div id="wb_Image3" style="margin:0;padding:0;position:absolute;left:336px;top:366px;width:155px;heigh
    t:259px;text-align:left;z-index:5;">
  41. <a href="./gifts1/kategorie1.html"><img src="images/gift.png" id="Image3" alt="" border="0" style="width:155px;height:259px;"></a></div>
  42. <div id="wb_Text5" style="margin:0;padding:0;position:absolute;left:337px;top:599px;width:154px;heigh
    t:16px;text-align:center;z-index:6;">
  43. <font style="font-size:13px" color="#000000" face="Arial">Nazwa kategorii 1</font></div>
  44. <div id="wb_Shape8" style="margin:0;padding:0;position:absolute;left:338px;top:405px;width:151px;heigh
    t:183px;text-align:center;z-index:7;">
  45. <img src="images/img0012.gif" id="Shape8" alt="" title="" style="border-width:0;width:151px;height:183px"></div>
  46. <div id="wb_Image2" style="margin:0;padding:0;position:absolute;left:537px;top:366px;width:155px;heigh
    t:259px;text-align:left;z-index:8;">
  47. <a href="./gifts2/kategorie2.html"><img src="images/gift.png" id="Image2" alt="" border="0" style="width:155px;height:259px;"></a></div>
  48. <div id="wb_Text4" style="margin:0;padding:0;position:absolute;left:538px;top:599px;width:154px;heigh
    t:16px;text-align:center;z-index:9;">
  49. <font style="font-size:13px" color="#000000" face="Arial">Nazwa kategorii 2</font></div>
  50. <div id="wb_Shape7" style="margin:0;padding:0;position:absolute;left:539px;top:405px;width:151px;heigh
    t:183px;text-align:center;z-index:10;">
  51. <img src="images/img0013.gif" id="Shape7" alt="" title="" style="border-width:0;width:151px;height:183px"></div>
  52. <div id="wb_Image5" style="margin:0;padding:0;position:absolute;left:737px;top:366px;width:155px;heigh
    t:259px;text-align:left;z-index:11;">
  53. <a href="./gifts3/kategorie3.html"><img src="images/gift.png" id="Image5" alt="" border="0" style="width:155px;height:259px;"></a></div>
  54. <div id="wb_Text7" style="margin:0;padding:0;position:absolute;left:740px;top:598px;width:154px;heigh
    t:16px;text-align:center;z-index:12;">
  55. <font style="font-size:13px" color="#000000" face="Arial">Nazwa kategorii 3</font></div>
  56. <div id="wb_Shape10" style="margin:0;padding:0;position:absolute;left:739px;top:405px;width:151px;heigh
    t:183px;text-align:center;z-index:13;">
  57. <img src="images/img0014.gif" id="Shape10" alt="" title="" style="border-width:0;width:151px;height:183px"></div>
  58.  
  59. </body>
  60. </html>
  61. <?php } ?>


Ten post edytował kiepski96 11.12.2010, 10:25:24
Go to the top of the page
+Quote Post
lord2105
post 11.12.2010, 12:06:31
Post #4





Grupa: Zarejestrowani
Postów: 380
Pomógł: 59
Dołączył: 24.04.2010
Skąd: London

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


pokaz plik logowania, w ktorym ustawiasz zmienna sesyjna $_SESSION['username']


--------------------
40% rozwiązań znajduje się tutaj.
59,9% tutaj.

Jeśli pomogłem rozwiązać Twój problem wciśnij
Go to the top of the page
+Quote Post
kiepski96
post 11.12.2010, 13:59:17
Post #5





Grupa: Zarejestrowani
Postów: 233
Pomógł: 0
Dołączył: 22.02.2010

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


Tutaj skrypt logowania:

  1. <?php
  2. if($_SERVER['REQUEST_METHOD'] == 'POST')
  3. {
  4. $success_page = './Kategorie.php';
  5. $error_page = './error.html';
  6. $mysql_server = 'localhost';
  7. $mysql_username = 'xxx';
  8. $mysql_password = 'xxx';
  9. $mysql_database = 'xxx';
  10. $mysql_table = 'reg1';
  11. $crypt_pass = md5($_POST['password']);
  12. $found = false;
  13. $fullname = '';
  14.  
  15. $db = mysql_connect($mysql_server, $mysql_username, $mysql_password);
  16. mysql_select_db($mysql_database, $db);
  17. $sql = "SELECT password, fullname, active FROM ".$mysql_table." WHERE username = '".$_POST['username']."'";
  18. $result = mysql_query($sql, $db);
  19. if ($data = mysql_fetch_array($result))
  20. {
  21. if ($crypt_pass == $data['password'] && $data['active'] != 0)
  22. {
  23. $found = true;
  24. $fullname = $data['fullname'];
  25. }
  26. }
  27. if($found == false)
  28. {
  29. header('Location: '.$error_page);
  30. }
  31. else
  32. {
  33. $_SESSION['username'] = $_POST['username'];
  34. $_SESSION['fullname'] = $fullname;
  35. header('Location: '.$success_page);
  36. }
  37. }
  38. $username = isset($_COOKIE['username']) ? $_COOKIE['username'] : '';
  39. $password = isset($_COOKIE['password']) ? $_COOKIE['password'] : '';
  40. ?>
  41. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  42. <html>
  43. <head>
  44. <meta http-equiv="Content-Language" content="pl">
  45. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  46. <title>Restockerz Script Pro</title>
  47. <meta name="keywords" content="script,restockerz">
  48. <meta name="author" content="domino1">
  49. <meta name="categories" content="Restock script">
  50. <link rel="shortcut icon" href="favicon.ico">
  51. <style type="text/css">
  52. body
  53. {
  54. background-color: #000000;
  55. color: #000000;
  56. }
  57. </style>
  58. </head>
  59. <body>
  60. <div id="wb_Shape1" style="margin:0;padding:0;position:absolute;left:0px;top:100px;width:1276px;height
    :40px;text-align:center;z-index:0;">
  61. <img src="images/img0001.png" id="Shape1" alt="" title="" style="border-width:0;width:1276px;height:40px"></div>
  62. <div id="wb_Image1" style="margin:0;padding:0;position:absolute;left:15px;top:0px;width:200px;height:1
    00px;text-align:left;z-index:1;">
  63. <img src="images/logo.png" id="Image1" alt="" border="0" style="width:200px;height:100px;"></div>
  64. <div id="wb_Shape2" style="margin:0;padding:0;position:absolute;left:51px;top:105px;width:81px;height:
    28px;text-align:center;z-index:2;">
  65. <a href="./index.php"><img src="images/img0002.png" id="Shape2" alt="" title="" style="border-width:0;width:81px;height:28px"></a></div>
  66. <div id="wb_Shape3" style="margin:0;padding:0;position:absolute;left:149px;top:105px;width:81px;height
    :28px;text-align:center;z-index:3;">
  67. <a href="./symulator.php"><img src="images/img0003.png" id="Shape3" alt="" title="" style="border-width:0;width:81px;height:28px"></a></div>
  68. <div id="wb_Shape4" style="margin:0;padding:0;position:absolute;left:247px;top:105px;width:81px;height
    :28px;text-align:center;z-index:4;">
  69. <a href="./pomoc.php"><img src="images/img0004.png" id="Shape4" alt="" title="" style="border-width:0;width:81px;height:28px"></a></div>
  70. <div id="wb_Login2" style="margin:0;padding:0;position:absolute;left:470px;top:322px;width:265px;heigh
    t:143px;text-align:left;z-index:5;">
  71. <form name="loginform" method="post" action="<?php echo basename(__FILE__); ?>" id="loginform">
  72. <table cellspacing="6" cellpadding="0" style="background-color:#388E8E;border-color:#388E8E;border-width:1px;border-style:solid;color:#000000;font-family:Times New Roman;font-size:17px;width:265px;height:143px;">
  73. <tr>
  74. <td colspan="2" align="center" style="height:23px;background-color:#DFE9F5;color:#387AC8;">Logowanie</td>
  75. </tr>
  76. <tr>
  77. <td align="left" style="height:21px;width:70px">Nick:</td>
  78. <td align="left"><input name="username" type="text" id="username" value="<?php echo $username; ?>" style="width:150px;height:18px;background-color:#FFFFFF;border-color:#DFE9F5;border-width:1px;border-style:solid;color:#000000;font-family:Times New Roman;font-size:17px;"></td>
  79. </tr>
  80. <tr>
  81. <td align="left" style="height:21px">Hasło:</td>
  82. <td align="left"><input name="password" type="password" id="password" value="<?php echo $password; ?>" style="width:150px;height:18px;px;background-color:#FFFFFF;border-color:#DFE9F5;border-width:1px;border-style:solid;color:#000000;font-family:Times New Roman;font-size:17px;"></td>
  83. </tr>
  84. <tr>
  85. <td>&nbsp;</td><td align="left" valign="bottom"><input type="image" name="login" id="login" src="images/loginbutton.png"></td>
  86. </tr>
  87. </table>
  88. </form>
  89. </div>
  90. <div id="wb_Shape6" style="margin:0;padding:0;position:absolute;left:346px;top:105px;width:81px;height
    :28px;text-align:center;z-index:6;">
  91. <a href="./Rejestracja.php"><img src="images/img0089.png" id="Shape6" alt="" title="" style="border-width:0;width:81px;height:28px"></a></div>
  92. </body>
  93. </html>
Go to the top of the page
+Quote Post
lord2105
post 11.12.2010, 14:07:15
Post #6





Grupa: Zarejestrowani
Postów: 380
Pomógł: 59
Dołączył: 24.04.2010
Skąd: London

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


  1. if($found == false)// tutaj zmienna found deklarowana jest wyzej na false wiec else sie nie wykona
  2. {
  3. header('Location: '.$error_page);
  4. }
  5. else
  6. {
  7. $_SESSION['username'] = $_POST['username'];
  8. $_SESSION['fullname'] = $fullname;
  9. header('Location: '.$success_page);
  10. }
  11.  


--------------------
40% rozwiązań znajduje się tutaj.
59,9% tutaj.

Jeśli pomogłem rozwiązać Twój problem wciśnij
Go to the top of the page
+Quote Post
kiepski96
post 13.12.2010, 09:39:57
Post #7





Grupa: Zarejestrowani
Postów: 233
Pomógł: 0
Dołączył: 22.02.2010

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


Teraz zmieniłem w skrypcie logowania wartość false na true i przy próbie zalogowania pojawia się,że podano błędne dane,choć są ok.

  1. if($found == true)// tutaj zmieniłem z false na true
  2. {
  3. header('Location: '.$error_page);
  4. }
  5. else
  6. {
  7. $_SESSION['username'] = $_POST['username'];
  8. $_SESSION['fullname'] = $fullname;
  9. header('Location: '.$success_page);
  10. }


Odpowiecie?

Ten post edytował kiepski96 11.12.2010, 14:40:00
Go to the top of the page
+Quote Post
strife
post 13.12.2010, 12:41:37
Post #8





Grupa: Przyjaciele php.pl
Postów: 2 605
Pomógł: 96
Dołączył: 22.10.2004
Skąd: UK

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


Po pierwsze to ja na Przedszkole pozwolę sobie to przenieść. A po drugie skoro autoryzacja zawodzi, po zapytaniu, które ma za zadanie sprawdzać uprawnienia użytkownika, daj coś takiego:

  1. $sql = "SELECT password, fullname, active FROM ".$mysql_table." WHERE username = '".$_POST['username']."'";
  2. echo $sql;
  3. die();


A zapytanie, które się wydrukuje wklej do konsoli mysql i sprawdź czy się wykona bez błędów (Dodam, że przy takiej konstrukcji Twojego kodu do sprawdzania błędów można skorzystać z mysql_error). Wtedy będziesz miał pewność, że na poziomie sprawdzania w bazie danych jest wszystko ok.

Jak wszystko pójdzie ok, następnym krokiem będzie sprawdzanie zmiennej $found, w tym celu wciśnij pomiędzy 26-27 kod, typu:

  1. echo "<pre>";
  2. var_export($found);
  3. echo "</pre>";
  4. die();


Wtedy sprawdzisz jaką wartość przyjmuje zmienna, która na końcu skryptu odpowiada za udzielanie uprawnień. Krótko mówiąc metodą prób i błędów małymi kroczkami idź w dół, aż znajdziesz przyczynę błędów. Umiejętność diagnozowania kodu to podstawowa umiejętność i musisz ją nabyć, aby swobodnie łatać kod winksmiley.jpg


--------------------
Go to the top of the page
+Quote Post
kiepski96
post 13.12.2010, 15:38:51
Post #9





Grupa: Zarejestrowani
Postów: 233
Pomógł: 0
Dołączył: 22.02.2010

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


Dodam,że temat umieściłem w przedszkole,ale ktoś przeniósł.

I dzięki za pomoc

Ten post edytował kiepski96 13.12.2010, 15:40:19
Go to the top of the page
+Quote Post
--koza--
post 29.08.2012, 23:12:26
Post #10





Goście







Wpisałem ten kod php na początku strony którą chce zastrzeżyć i po podaniu poprawnych danych do logowania (mam pewność że baza danych działa poprawnie)
wywala komunikat :
Nieprawidłowe przekierowanie
Firefox wykrył, że serwer przekierowuje żądanie tego zasobu w sposób uniemożliwiający jego ukończenie.



jakieś pomysły?
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: 30.05.2024 - 13:54