Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> problem z ciastkami ;(, pomocy, mam problem z ciachami...
-D4rky-
post
Post #1





Goście







help. mam problem z ciachami. zrobilem skrypt logowania ktory wyglada mniej wiecej tak

(fragment z menu)
  1. <?
  2. @$user = $HTTP_COOKIE_VARS[&#092;"user\"];
  3. echo($user);
  4. if($user == &#092;"\")
  5. {
  6. include(&#092;"data/login.frm\");
  7. }
  8. else
  9. {
  10. include(&#092;"data/logged.frm\");
  11. }
  12. ?>  


tabelka do zalogowania
  1. <?php
  2.  
  3. <form method=&#092;"POST\" action=\"index.php?page=login\">
  4.  <p align=&#092;"center\"><font face=\"Courier\" size=\"2\">Użytkownik</font><input type=\"text\" name=\"user\" size=\"16\" style=\"background-color: #000000; font-family: Courier; color: #FFFFFF; font-size: 8pt; border: 2 solid #808080\"><br>
  5. <font face=&#092;"Courier\" size=\"2\">Hasło</font><input type=\"text\" name=\"haslo\" size=\"16\" style=\"background-color: #000000; font-family: Courier; color: #FFFFFF; font-size: 8pt; border: 2 solid #808080\"><br>
  6. <input type=&#092;"submit\" value=\"Zaloguj\" style=\"background-color: #000000; color: #FFFFFF; font-family: Courier; font-size: 10pt; border: 2 solid #808080\"><br>
  7. <font size=&#092;"1\" face=\"Verdana\"><a href=\"index.php?page=register\"?Zarejestruj się</a></font></p>
  8. </form>
  9.  
  10. ?>


tabelka PO zalogowaniu
  1. <? @$user = $HTTP_COOKIE_VARS[&#092;"user\"]; ?>
  2. Witaj <? 
  3. echo($user);
  4. ?>.<br>
  5. Edytuj dane użytkownika<br>
  6. Napisz FF<br>
  7. Wyloguj<br>


i najwazniejsze - sprawdzanie hasla i zapisywanie cookie
  1. <?
  2. @$pass = $_POST[&#092;"haslo\"];
  3. @$user = $_POST[&#092;"user\"];
  4. @$akcja = $_POST[&#092;"akcja\"];
  5.  
  6. function readArray($fd)
  7. {
  8. $arr = array();
  9. while (!feof ($fd)) {
  10.  $line = trim(fgets($fd));
  11.  if(($pos = strpos($line, &#092;":\"))===false) continue;
  12.  
  13.  $tempUser = substr($line, 0, $pos);
  14.  $tempPass = substr($line, $pos + 1, strlen($line) - $pos);
  15.  if ($tempUser == '' || $tempPass == '') continue;
  16.  
  17.  $arr[$tempUser] = $tempPass;
  18. }
  19. return $arr;
  20. }
  21.  
  22. function writeArray($fd, $arr)
  23. {
  24. foreach ($arr as $key => $value){
  25.  $tempStr = $key.&#092;":\".$value.\"rn\";
  26.  fwrite($fd, $tempStr);
  27. }
  28. }
  29.  
  30. if($pass == &#092;"\" && $akcja != \"remove\"){
  31. echo(&#092;"Brak hasła!\");
  32. return;
  33. }
  34. if($user == &#092;"\"){
  35. echo(&#092;"Brak nazwy użytkownika!\");
  36. return;
  37. }
  38.  
  39. if(!$fd = @fopen(&#092;"passwords.txt\", \"a+\")){
  40. echo(&#092;"Błąd przy próbie otwarcia pliku\");
  41. return;
  42. }
  43.  
  44. fseek($fd, 0);
  45. $arr = readArray($fd);
  46. fclose($fd);
  47.  
  48. if($akcja == &#092;"add\"){
  49. if(!array_key_exists($user, $arr)){
  50.  $arr[$user] = md5($pass);
  51.  echo(&#092;"Użytkownik: $user został dodany do bazy!\");
  52. }
  53. else{
  54.  echo(&#092;"Użytkownik: $user istnieje już w bazie!\");
  55.  return;
  56. }
  57. }
  58. else if ($akcja == &#092;"remove\"){
  59. if(array_key_exists($user, $arr)){
  60.  unset($arr[$user]);
  61.  echo(&#092;"Użytkownik: $user został usunięty z bazy!\");
  62. }
  63. else{
  64.  echo(&#092;"Nie ma użytkownika: $user w bazie!\");
  65.  return;
  66. }
  67. }
  68. else if ($akcja == &#092;"modify\"){
  69. if(array_key_exists($user, $arr)){
  70.  $arr[$user] = md5($pass);
  71.  echo(&#092;"Hasło użytkownika: $user zostało zmienione!\");
  72. }
  73. else{
  74.  echo(&#092;"Nie ma użytkownika: $user w bazie!\");
  75.  return;
  76. }
  77. }
  78. else{
  79. echo(&#092;"Błędne dane: akcja=$akcja\");
  80. return;
  81. }
  82.  
  83. if(!$fd = @fopen(&#092;"passwords.txt\", \"w\")){
  84. echo(&#092;"Wstąpił błąd przy próbie zapisu zmodyfikowanej bazy!\");
  85. return;
  86. }
  87. writeArray($fd, $arr);
  88. fclose($fd);
  89. ?>


ale gdzies jest blad bo ciastka sie nie zapisuja, i jak przejde do innej podstrony jest znowu wylogowany. czy znajdzie sie ktos na tyle laskawy zeby pomoc?

jestem kompletny n00b wiec jak cos jest zjechane to mozecie mnie objezdzac (IMG:http://forum.php.pl/style_emoticons/default/sadsmiley02.gif)
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 11)
-D4rky-
post
Post #2





Goście







moze byc troche zbednych kodow, np. kilka razy wpisywanie ciacha ale to dlatego ze probowalem juz wszystkiego co potrafilem wymozdzyc.

uzywam Lycos'a
Go to the top of the page
+Quote Post
hwao
post
Post #3


Developer


Grupa: Moderatorzy
Postów: 2 844
Pomógł: 20
Dołączył: 25.11.2003
Skąd: Olkusz




Po 1 pochwala za uzycie bbcode :-) masz +

Co do porblemu to nie wiem cyz lycos nie uzywa nowszych tablic czyli zamiast
  1. <? @$user = $HTTP_COOKIE_VARS[&#092;"user\"]; ?>


to

  1. <? @$user = $_COOKIE[&#092;"user\"]; ?>


Sprawdz moze pomoze :-)
Go to the top of the page
+Quote Post
-D4rky-
post
Post #4





Goście







nie. właśnie próbowałem tego HTTP_VARSA, bo $_COOKIE nie działało (IMG:http://forum.php.pl/style_emoticons/default/sadsmiley02.gif)
Go to the top of the page
+Quote Post
-D4rky-
post
Post #5





Goście







help. już nikt się nie zlituje? plizz potrzebuję pomocy!
  1. <?
  2. include(&#092;"help.me\");
  3. ?>


Ae teraz poważniej. może ktoś zna odpowiedź na to jak ma działać? Widziałem, że ktoś też ma problem z cookiesami. Kurde co jest, IE ma ochotę na ciastka, że je połyka?? (IMG:http://forum.php.pl/style_emoticons/default/sadsmiley02.gif) (IMG:http://forum.php.pl/style_emoticons/default/sadsmiley02.gif) (IMG:http://forum.php.pl/style_emoticons/default/sadsmiley02.gif)
Go to the top of the page
+Quote Post
-D4rky-
post
Post #6





Goście







ludzie litości, ja na prawdę potrzebuję pomocy. chociaż piszcie, że nie wiecie (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
Cytat
POMOCCCCCCYYY
Go to the top of the page
+Quote Post
gilbo
post
Post #7





Grupa: Zarejestrowani
Postów: 169
Pomógł: 1
Dołączył: 16.04.2004
Skąd: z domu

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


A może masz wyłączone ciacha (IMG:http://forum.php.pl/style_emoticons/default/winksmiley.jpg)
Go to the top of the page
+Quote Post
-D4rky-
post
Post #8





Goście







to nie to. nadal nie działa (IMG:http://forum.php.pl/style_emoticons/default/sadsmiley02.gif)
sprawdziłem na najniższym poziomie zabezpieczeń i nic...
Go to the top of the page
+Quote Post
-D4rky-
post
Post #9





Goście







a ma ktoś pomysł alternatywny, tzn. zamiast ciastek? jak mógłbym to zrobić w sesjach czy cuś (IMG:http://forum.php.pl/style_emoticons/default/sad.gif)
Go to the top of the page
+Quote Post
-Guest-
post
Post #10





Goście







używaj $_COOKIE['nazwa'] .
Podaj kawałek kodu gdzie ustawiasz ciastka.
Go to the top of the page
+Quote Post
peterj
post
Post #11





Grupa: Zarejestrowani
Postów: 121
Pomógł: 0
Dołączył: 9.02.2004
Skąd: Warszawa

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


Cytat(D4rky @ 2004-12-30 02:06:12)
tabelka do zalogowania
  1. <?php
  2. <form method=&#092;"POST\" action=\"index.php?page=login\">
  3.            <p align=&#092;"center\"><font face=\"Courier\" size=\"2\">Użytkownik</font><input type=\"text\" name=\"user\" size=\"16\" style=\"background-color: #000000; font-family: Courier; color: #FFFFFF; font-size: 8pt; border: 2 solid #808080\"><br>
  4.           <font face=&#092;"Courier\" size=\"2\">Hasło</font><input type=\"text\" name=\"haslo\" size=\"16\" style=\"background-color: #000000; font-family: Courier; color: #FFFFFF; font-size: 8pt; border: 2 solid #808080\"><br>
  5.           <input type=&#092;"submit\" value=\"Zaloguj\" style=\"background-color: #000000; color: #FFFFFF; font-family: Courier; font-size: 10pt; border: 2 solid #808080\"><br>
  6.           <font size=&#092;"1\" face=\"Verdana\"><a href=\"index.php?page=register\"?Zarejestruj się</a></font></p>
  7.         </form>
  8. ?>

Sama tableka (a raczej formularz) powinien zwrócić błąd :]
Zmień to na:
  1. <?php
  2. echo &#092;"<form method=\"POST\" action=\"index.php?page=login\">
  3.            <p align=&#092;"center\"><font face=\"Courier\" size=\"2\">Użytkownik</font><input type=\"text\" name=\"user\" size=\"16\" style=\"background-color: #000000; font-family: Courier; color: #FFFFFF; font-size: 8pt; border: 2 solid #808080\"><br>
  4.           <font face=&#092;"Courier\" size=\"2\">Hasło</font><input type=\"text\" name=\"haslo\" size=\"16\" style=\"background-color: #000000; font-family: Courier; color: #FFFFFF; font-size: 8pt; border: 2 solid #808080\"><br>
  5.           <input type=&#092;"submit\" value=\"Zaloguj\" style=\"background-color: #000000; color: #FFFFFF; font-family: Courier; font-size: 10pt; border: 2 solid #808080\"><br>
  6.           <font size=&#092;"1\" face=\"Verdana\"><a href=\"index.php?page=register\"?Zarejestruj się</a></font></p>
  7.         </form>&#092;";
  8. ?>


W tym kodzie co tu podałeś nie ma ani słowa o zapisywaniu ciastka.
Może zastosować setcookie (IMG:http://forum.php.pl/style_emoticons/default/winksmiley.jpg)

Ten post edytował peterj 1.01.2005, 02:58:56
Go to the top of the page
+Quote Post
-_Darky_-
post
Post #12





Goście







ROTFL!!!! nie podałem najważniejszego (IMG:http://forum.php.pl/style_emoticons/default/haha.gif) .
Ta tabelka nie sprawdza i nie zapisuje cookie tylko dodaje użytkownika (IMG:http://forum.php.pl/style_emoticons/default/haha.gif) .
Oto plik od logowania
  1. <?
  2. @$pass = $_POST[&#092;"haslo\"];
  3. @$user = $_POST[&#092;"user\"];
  4.  
  5. function checkPass($pass, $user)
  6. {
  7. if(!$fd = @fopen(&#092;"passwords.txt\", \"r\")) return false;
  8. while (!feof ($fd)) {
  9. $line = trim(fgets($fd));
  10. if(($pos = strpos($line, &#092;":\"))===false) continue;
  11. $tempUser = substr($line, 0, $pos);
  12. if($tempUser !=$user) continue;
  13. $tempPass = substr($line, $pos + 1,strlen($line) - $pos);
  14. if($tempPass != md5($pass)) continue;
  15. else return true;
  16. }
  17. fclose($fd);
  18. return false;
  19. }
  20. if(!checkPass($pass, $user))
  21. {
  22. echo('Niepoprawne dane.');
  23. }
  24. else
  25. {
  26. setcookie(&#092;"user\", $user, time()+3600);
  27. echo('Witaj '.$user);
  28. }
  29. ?>

A co do formularza: pomyliłem się, bo to HTML nie php i tam w ogóle nie powinno być echo (IMG:http://forum.php.pl/style_emoticons/default/biggrin.gif)
No ale teraz może ktoś będzie wiedział?
http://www.members.lycos.co.uk/blazekien/ffzone
login: maker
pass: me

tylko plz nie kradnijcie mojego pomysłu, podaję, żebyście sami zobaczyli, że nie działa (IMG:http://forum.php.pl/style_emoticons/default/tongue.gif)
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: 15.09.2025 - 07:05