Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

2 Stron V   1 2 >  
Reply to this topicStart new topic
> [PHP]Automatyczne pzekierowanie po zalogowaniu
--ewelina--
post 4.07.2012, 18:15:57
Post #1





Goście







Witam

prosze o pomoc
mam skrypcik logowania ale niewiem co dodac aby automatycznie po zalogowaniu pzekierowało usera do jego profilu.
prubowałam dodac header("profile.php?id='.$user['id'].'");
ale nic z tego.
prubowałam echo "<script>window.location.href="profile.php?id='.$user['id'].";</script> i nic

  1. <?php
  2.  
  3. require 'header.php';
  4. require 'include/config.php';
  5. require_once 'user.class.php';
  6. ?>
  7. <?php
  8. if (user::isLogged()) {
  9.  
  10. $user = user::getData('', '');
  11.  
  12. echo '<center><font color="#00FF00">Jesteś zalogowany, witaj '.$user['login'].'!</font></center><center><font color="#00FF00">Możesz zobaczyć swój <a href="profile.php?id='.$user['id'].'">profil</a> albo się <a href="logout.php">wylogować</a></font></center><br>
  13. ';
  14. }
  15.  
  16. else {
  17.  
  18. echo '<div align="center"<center><p><font color="#CCCCCC">Nie jesteś zalogowany. <img src="images/niezal.png" width="30" height="30" /><br /><a href="login.php">Zaloguj</a> się lub <a href="register.php">zarejestruj</a> jeżeli jeszcze nie masz konta.</font></p></center></div>
  19. ';
  20. }
  21. require 'include/menu.tpl';
  22. require 'footer.php';
  23.  
  24. ?>
Go to the top of the page
+Quote Post
CuteOne
post 4.07.2012, 18:28:57
Post #2





Grupa: Zarejestrowani
Postów: 2 958
Pomógł: 574
Dołączył: 23.09.2008
Skąd: wiesz, że tu jestem?

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


  1. header("Location: http:// mojastrona.pl /profile.php?id=".$user['id']);


bez spacji w adresie

Ten post edytował CuteOne 4.07.2012, 18:29:11
Go to the top of the page
+Quote Post
-Gość-
post 4.07.2012, 18:29:25
Post #3





Goście







Sprobuj
  1. header('location: profile?id=".$user['id']."');
Go to the top of the page
+Quote Post
--ewelina--
post 5.07.2012, 07:44:42
Post #4





Goście







witam
dzieki wszystko działa.

a jeszcze jedno dlaczego jak pokazuje profil to w adresie strony nie pokazuje mi profil.php?nazwa usera tylko jego id z bazy jak zrobic aby nie
pokazywało id tylko nazwe usera.
Go to the top of the page
+Quote Post
Shido
post 5.07.2012, 07:57:44
Post #5





Grupa: Zarejestrowani
Postów: 121
Pomógł: 22
Dołączył: 22.06.2012

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


Ponieważ uzyskujesz dane z poprzez id, musisz przerobić swój skrypt by pobierał dane na temat usera po jego nicku, a nie id, dodatkowo wszędzie tam gdzie nawiązujesz do strony z profilem ( linki/przenoszenie ) musisz pozmieniać skrypt tak by również tam pojawiał się nick, a nie id.


--------------------
Sorka za błędy ort. jak coś dajcie znać na PW to popoprawiam.
Go to the top of the page
+Quote Post
-Gość-
post 5.07.2012, 08:00:57
Post #6





Goście







  1. header('location: profile.php?id=".$user['login']."');
Go to the top of the page
+Quote Post
Lorum3
post 5.07.2012, 08:31:09
Post #7





Grupa: Zarejestrowani
Postów: 86
Pomógł: 5
Dołączył: 10.12.2011
Skąd: Poznań

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


Cytat(Gość @ 5.07.2012, 09:00:57 ) *
  1. header('location: profile.php?id=".$user['login']."');


Dodatkowo popraw w zapytaniu ( klasa User), aby pobierał dane na podstawie loginu, a nie id ( WHERE).
Go to the top of the page
+Quote Post
--ewelina--
post 5.07.2012, 10:06:43
Post #8





Goście







dzieki działa

a jeszcze moze macie jakiegos linka do tutka jak zintegrowac ten edytor http://ckeditor.com/ z php
Go to the top of the page
+Quote Post
amii
post 5.07.2012, 10:52:29
Post #9





Grupa: Zarejestrowani
Postów: 728
Pomógł: 76
Dołączył: 12.06.2009

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


Tu masz omówioną integrację ze stroną implementującą jQuery:
http://docs.cksource.com/CKEditor_3.x/Deve.../jQuery_Adapter

generlanie wystarczy, że wkleisz w sekcji head, oczywiscie parametry sobie regulujesz np. height po za tym lepiej zgrać pliki na swój serwer a nie zasysać z zewnętrznego źródła:
[JAVASCRIPT] pobierz, plaintext
  1. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
  2. <script type="text/javascript" src="/ckeditor/ckeditor.js"></script>
  3. <script type="text/javascript" src="/ckeditor/adapters/jquery.js"></script>
  4. <script language="javascript">
  5. $(document).ready(function(){
  6. $('textarea').ckeditor({ height : 500 });
  7. });
  8. </script>
[JAVASCRIPT] pobierz, plaintext


--------------------
gry flash online
Dobry hosting i tanie odnowienia domen firma: masternet.
Zarabianie bez wysiłku na domenach bez ruchu: prolink.
Go to the top of the page
+Quote Post
--ewelina--
post 5.07.2012, 11:02:50
Post #10





Goście







znowu problem

nmieniłam to z tym id dodałam login i ok wyświetla sie login ale teraz nie pokazuje mi zawartości imie itd.
sory ze tak marudze ale dopiero sie ucze.
podaje kod profilu moze cos zle robie.
  1. <?php
  2.  
  3. require 'header.php';
  4. require 'include/config.php';
  5. require_once 'user.class.php';
  6.  
  7. if (!user::isLogged()) {
  8. echo '<center><font color="#ff0000"><p class="error">Przykro nam, ale ta strona jest dostepna tylko dla zalogowanych.</p></font></center>';
  9. }
  10.  
  11. else {
  12. $login = $_GET['login'];
  13.  
  14. $userExist = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM users WHERE login = '$login'"));
  15.  
  16. if ($userExist[0] == 0) {
  17. die ('<center><font color="#ff0000"><p>Przykro nam, ale uzytkownik o podanym identyfikatorze nie istnieje.</p></font></center>');
  18. }
  19.  
  20. $profile = user::getDataById ($login);
  21. require'include/menu_user.tpl';
  22. echo '';
  23.  
  24. }
  25. require'include/profile.tpl';
  26. require 'footer.php';
  27.  
  28. ?>
Go to the top of the page
+Quote Post
Shido
post 5.07.2012, 11:08:52
Post #11





Grupa: Zarejestrowani
Postów: 121
Pomógł: 22
Dołączył: 22.06.2012

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


  1. $profile = user::getDataById ($login);

Klasa jest nauczona uzupełniać się po id.
Wejdź w plik user.class.php i tam w funkcji getDataById zmień pobieranie danych z id na login


--------------------
Sorka za błędy ort. jak coś dajcie znać na PW to popoprawiam.
Go to the top of the page
+Quote Post
-eewelina-
post 5.07.2012, 12:07:58
Post #12





Goście







no ok loguj i pokazuje zmieniłam to w tym user.class
ale dalej nie wyświetla danych jak mam taka tabele to nie pokazuje
tam gdzie jes $profile['login'] i inne to nic sie nie wyswietla a wczesniej jak było na id to było ok
  1. <div class="div"><center><font color="#999999"><h3>Profil uzytkownika '.$profile['login'].'</h3></font></center></div>
  2. <table class="tableq" cellpadding="10" cellspacing="0">
  3. <tr></tr>
  4. <tr>
  5. <td width="200" align="center" class="td1"><font color="#CCCCCC"><b>Nick:</b></font></td>
  6. <td align="center" class="td3"><font color="#CCCCCC">'.$profile['login'].'</font></td>
  7. <tr>
  8. <td width="200" align="center" class="td1"><font color="#CCCCCC"><b>Email:</b></font></td>
  9. <td align="center" class="td3"><font color="#CCCCCC">'.$profile['email'].'</font></td>
  10. </tr>
  11. <tr>
  12. <td width="200" align="center" class="td1"><font color="#CCCCCC"><b>Imie:</b></font></td>
  13. <td align="center" class="td3"><font color="#CCCCCC">'.$profile['imie'].'</font></td>
  14. </tr>
  15. <tr>
  16. <td width="200" align="center" class="td1"><font color="#CCCCCC"><b>Nazwisko:</b></font></td>
  17. <td align="center" class="td3"><font color="#CCCCCC">'.$profile['nazwisko'].'</font></td>
  18. </tr>
  19. <tr>
  20. <td width="200" align="center" class="td1"><font color="#CCCCCC"><b>Miasto:</b></font></td>
  21. <td align="center" class="td3"><font color="#CCCCCC">'.$profile['miasto'].'</font></td>
  22. </tr>
  23. <tr>
  24. <td width="200" align="center" class="td1"><font color="#CCCCCC"><b>Numer gg:</b></font></td>
  25. <td align="center" class="td3"><font color="#CCCCCC">'.$profile['gg'].'</font></td>
  26. </tr>
  27. <tr>
  28. <td width="200" align="center" class="td1"><font color="#CCCCCC"><b>Skype:</b></font></td>
  29. <td align="center" class="td3" ><font color="#CCCCCC">'.$profile['skype'].'</font></td>
  30. </tr>
  31. <tr>
  32. <td align="center"><a href="editprofile.php">edztuj</a></td>
  33. </table>';

podaje ci
skrypt profile
  1. <?php header('Content-type: text/html; charset=utf-8'); ?>
  2. <?php
  3. /**
  4.  * Profil
  5.  * @author Sobak
  6.  * @package User System
  7.  */
  8.  
  9. require 'header.php';
  10. require 'include/config.php';
  11. require_once 'user.class.php';
  12.  
  13. if (!user::isLogged()) {
  14. echo '<center><font color="#ff0000"><p class="error">Przykro nam, ale ta strona jest dostepna tylko dla zalogowanych.</p></font></center>';
  15. }
  16.  
  17. else {
  18. $login = $_GET['login'];
  19.  
  20. */
  21. $userExist = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM users WHERE login = '$login'"));
  22.  
  23. if ($userExist[0] == 0) {
  24. die ('<center><font color="#ff0000"><p>Przykro nam, ale uzytkownik o podanym identyfikatorze nie istnieje.</p></font></center>');
  25. }
  26.  
  27. $profile = user::getDataById ($login);
  28.  
  29. echo '<style>
  30. .div
  31. {
  32. width:500px;
  33. height:30px;
  34. margin:0 auto;
  35. background-image:url(include/styles/default/images/fondotduser.png);
  36. border-radius:10px 10px 0px 0px ;
  37. }
  38. .tableq
  39. {
  40. width:500px;
  41. height: auto;
  42. background-color:#CCDBF2;
  43. margin:0 auto;
  44. border-radius:0px 0px 10px 10px ;
  45. box-shadow: 0 0 30px 5px #900 ;
  46. background-image:url(include/styles/default/images/fondoprofil.png);
  47. }
  48. .td1
  49. {
  50.  
  51. border-radius:0px 0px 0px 0px ;
  52. border-bottom:1px #000000 groove;
  53. border-right:2px #99CC00 ridge;
  54.  
  55. }
  56. .td2
  57. {
  58.  
  59. border-radius:0px 0px 0px 10px ;
  60. border-right:2px #99CC00 ridge;
  61. }
  62. .td3
  63. {
  64. border-bottom:1px #000000 groove;
  65. }
  66. .boton
  67. {
  68. width:100px;
  69. height:30px;
  70. background-image:url(include/styles/default/images/boton.png);
  71. border-radius:5px 5px 5px 5px;
  72.  
  73. }
  74. </style>
  75. <div class="div"><center><font color="#999999"><h3>Profil uzytkownika '.$profile['login'].'</h3></font></center></div>
  76. <table class="tableq" cellpadding="10" cellspacing="0">
  77. <tr></tr>
  78. <tr>
  79. <td width="200" align="center" class="td1"><font color="#CCCCCC"><b>Nick:</b></font></td>
  80. <td align="center" class="td3"><font color="#CCCCCC">'.$profile['login'].'</font></td>
  81. <tr>
  82. <td width="200" align="center" class="td1"><font color="#CCCCCC"><b>Email:</b></font></td>
  83. <td align="center" class="td3"><font color="#CCCCCC">'.$profile['email'].'</font></td>
  84. </tr>
  85. <tr>
  86. <td width="200" align="center" class="td1"><font color="#CCCCCC"><b>Imie:</b></font></td>
  87. <td align="center" class="td3"><font color="#CCCCCC">'.$profile['imie'].'</font></td>
  88. </tr>
  89. <tr>
  90. <td width="200" align="center" class="td1"><font color="#CCCCCC"><b>Nazwisko:</b></font></td>
  91. <td align="center" class="td3"><font color="#CCCCCC">'.$profile['nazwisko'].'</font></td>
  92. </tr>
  93. <tr>
  94. <td width="200" align="center" class="td1"><font color="#CCCCCC"><b>Miasto:</b></font></td>
  95. <td align="center" class="td3"><font color="#CCCCCC">'.$profile['miasto'].'</font></td>
  96. </tr>
  97. <tr>
  98. <td width="200" align="center" class="td1"><font color="#CCCCCC"><b>Numer gg:</b></font></td>
  99. <td align="center" class="td3"><font color="#CCCCCC">'.$profile['gg'].'</font></td>
  100. </tr>
  101. <tr>
  102. <td width="200" align="center" class="td1"><font color="#CCCCCC"><b>Skype:</b></font></td>
  103. <td align="center" class="td3" ><font color="#CCCCCC">'.$profile['skype'].'</font></td>
  104. </tr>
  105. <tr>
  106. <td align="center"><a href="editprofile.php">edztuj</a></td>
  107. </table>';
  108.  
  109.  
  110. }
  111.  
  112. require 'footer.php';
  113. ?>


i skrypt user.clas
  1. <?php
  2.  
  3. class user {
  4.  
  5. public static $user = array();
  6.  
  7. public function getData ($login, $pass) {
  8. if ($login == '') $login = $_SESSION['login'];
  9. if ($pass == '') $pass = $_SESSION['pass'];
  10.  
  11. self::$user = mysql_fetch_array(mysql_query("SELECT * FROM users WHERE login='$login' AND pass='$pass' LIMIT 1;"));
  12. return self::$user;
  13. }
  14.  
  15.  
  16. public function getDataById ($login) {
  17. $user = mysql_fetch_array(mysql_query("SELECT * FROM users WHERE id='$id' LIMIT 1;"));
  18. return $user;
  19. }
  20.  
  21. public function isLogged () {
  22. if (empty($_SESSION['login']) || empty($_SESSION['pass'])) {
  23. return false;
  24. }
  25.  
  26. else {
  27. return true;
  28. }
  29. }
  30.  
  31. public function passSalter ($pass) {
  32. $pass = '$@@#$#@$'.$pass.'q2#$3$%##@';
  33. return md5($pass);
  34. }
  35.  
  36. }


ja juz niewiem gdzie jest ten błąd
Go to the top of the page
+Quote Post
Shido
post 5.07.2012, 12:24:24
Post #13





Grupa: Zarejestrowani
Postów: 121
Pomógł: 22
Dołączył: 22.06.2012

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


user.class.php
  1. public function getDataById ($login) {
  2. $user = mysql_fetch_array(mysql_query("SELECT * FROM users WHERE login='$login' LIMIT 1;"));
  3. return $user;
  4. }

Teraz będzie działać.
Zmieniłaś tylko argument funkcji, a przede wszystkim było trzeba zmienić zapytanie w bazie danych.

Ten post edytował Shido 5.07.2012, 12:25:01


--------------------
Sorka za błędy ort. jak coś dajcie znać na PW to popoprawiam.
Go to the top of the page
+Quote Post
--ewelina--
post 6.07.2012, 11:02:00
Post #14





Goście







witam

jeszcze moze powieci mi dlaczego jak zaloguje sie jako uzytkownik ok wyświetla mi sie profil ale jak w menu chcę pzejsc na formularz.php to mi sie wswietla ze niema takiego usera. tak jakby zmienna nie pzechowywała ze user jest zalogowany. podaje wam
skrypt jaki mam z formularz.php

  1. <?php header('Content-type: text/html; charset=utf-8'); ?>
  2. <?php
  3.  
  4. require 'headertxt.php';
  5. require 'include/config.php';
  6. require_once 'user.class.php';
  7.  
  8. if (!user::isLogged()) {
  9. echo '<center><font color="#ff0000"><p class="error">Przykro nam, ale ta strona jest dostepna tylko dla zalogowanych.</p></font></center>';
  10. }
  11.  
  12. else {
  13. $login = $_GET['login'];
  14.  
  15. $userExist = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM users WHERE login = '$login'"));
  16.  
  17. if ($userExist[0] == 0) {
  18. die ('<center><font color="#ff0000"><p>Przykro nam, ale uzytkownik o podanym identyfikatorze nie istnieje.</p></font></center>');
  19. }
  20.  
  21.  
  22. $profile = user::getDataById ($login);
  23. require'include/menu_user.tpl';
  24. require'include/formularz.tpl';
  25. echo '';
  26. }
  27.  
  28. require 'footer.php';
  29.  
  30. ?>
Go to the top of the page
+Quote Post
redeemer
post 6.07.2012, 11:06:33
Post #15





Grupa: Zarejestrowani
Postów: 915
Pomógł: 210
Dołączył: 8.09.2009
Skąd: Tomaszów Lubelski/Wrocław

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


  1. if (!user::isLogged()) {
Brakuje $ przed user.
Pobieranie loginu ze zmiennej $_GET (z adresu) jest bardzo złym pomysłem. Login powinna zwracać klasa user na podstawie danych z sesji.

Ten post edytował redeemer 6.07.2012, 11:06:44


--------------------
Go to the top of the page
+Quote Post
--ewelina--
post 6.07.2012, 12:44:43
Post #16





Goście







to podpowiedz jak to zmienic aby było bezpieczniej
Go to the top of the page
+Quote Post
--ewelina--
post 6.07.2012, 12:48:58
Post #17





Goście







jak zmieniłam

(!user::isLogged())
na
(!$user::isLogged())

to mi wyskakuje taki blad
Fatal error: Class name must be a valid object or a string in C:\xampp\htdocs\new\formularz.php on line 9
Go to the top of the page
+Quote Post
--ewelina--
post 6.07.2012, 13:10:35
Post #18





Goście







jeszcze takie małe pytanko
jak skonstruawac baze danych mysql
tak aby danmu nato ze user sie rejestruje
i aby np. dodaje swoje adres email. i jak napzykład chciałby zapisać szablon w html to jak to zrobic zeby puzniej po ponownym zalogowaniu wyswietlały sie jego adresy email i szablony .
Go to the top of the page
+Quote Post
Shido
post 6.07.2012, 13:31:44
Post #19





Grupa: Zarejestrowani
Postów: 121
Pomógł: 22
Dołączył: 22.06.2012

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


Tabela userów, gdzie musi być id np:
id | nick | pass
tabela email np.
id | user | mail
tabela szablony np.
id | user | szablon

w email i szablony w polu user umieszczamy id usera który stworzy dany szablon/dodał e-mail.
A by to wyświetlić wyciągamy z bazy te rekordy gdzie pole user = id przeglądającego.


--------------------
Sorka za błędy ort. jak coś dajcie znać na PW to popoprawiam.
Go to the top of the page
+Quote Post
--ewelina--
post 6.07.2012, 13:57:14
Post #20





Goście







ok co do bazy to jeszcze poprubuje puzniej ale
z tym co pisałam wyzej jak sie zaloguje to pzekieruje mnie na profil i wszystko ok ale jak np pzejde z menu na formularz to wywal mi błąd ze nima takiego usera.
Go to the top of the page
+Quote Post

2 Stron V   1 2 >
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: 13.08.2025 - 10:08