Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [MySQL][PHP] Logowanie - dostęp do podstron
buddha
post 12.10.2017, 19:41:26
Post #1





Grupa: Zarejestrowani
Postów: 23
Pomógł: 0
Dołączył: 7.09.2017

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


Witajcie.

Postaram się wam opisać mój problem.

Moim głównym założeniem jest ustawienie na stronie głównej
formularza do wyszukiwania innych użytkowników, lecz niestety
po przejściu dalej zdjęcia oraz inne szczegółowe dane
użytkowników są nie widoczne.

Próbowałem wyłączyć logowanie czy też ustawić standard
na zalogowany, lecz cały portal ma w sobie bardzo wiele złożonych
funkcji. Myślę że jednym z sposobów będzie ustawienie dla każdej
nie zalogowanej osoby id

  1. function isLogged() {
  2.  
  3. global $mysqli;
  4.  
  5.  
  6.  
  7. if (!empty($_SESSION['user']) && is_numeric($_SESSION['user']) && $_SESSION['user'] > 0) {
  8.  
  9. $user_id = secureEncode($_SESSION['user']);
  10.  
  11. $query = "SELECT COUNT(id) AS count FROM usuarios WHERE id=$user_id";
  12.  
  13. $sql_query = $mysqli->query($query);
  14.  
  15. $sql_fetch = mysqli_fetch_assoc($sql_query);
  16.  
  17.  
  18.  
  19. return $sql_fetch['count'];
  20.  
  21. }
  22.  
  23. }


oraz

  1. function getSearchUserInfo($uid) {
  2. global $mysqli,$sm;
  3. $uid = secureEncode($uid);
  4. $user = $mysqli->query("SELECT id,name,city,country,online_day,age,fake,gender FROM users WHERE id = '".$uid."'");
  5. $u = $user->fetch_object();
  6. $first_name = explode(' ',trim($u->name));
  7. $first_name = explode('_',trim($first_name[0]));
  8. //CURENT USER
  9. $current_user['id'] = $u->id;
  10. $current_user['first_name'] = $first_name[0];
  11. $current_user['name'] = $u->name;
  12. $current_user['profile_photo'] = profilePhoto($u->id);
  13. $current_user['city'] = $u->city;
  14. $current_user['country'] = $u->country;
  15. $current_user['age'] = $u->age;
  16. $current_user['gender'] = $u->gender;
  17. $current_user['link'] = clean($first_name[0]);
  18. $current_user['fake'] = $u->fake;
  19. $current_user['online_day'] = $u->online_day;
  20. $sm['search'] = $current_user;
  21. }


Macie jakieś pomysły? Rozwiązanie zapewne banalne, ale cos nie moge wymyślić.

_____________________


Na początku pliku profile/content.php mam taki kod

  1. if($_GET['id'] != NULL ){
  2.  
  3. $usid = secureEncode($_GET['id']);
  4.  
  5. getUserInfo($usid,1);
  6.  
  7. }




Ten post edytował buddha 12.10.2017, 19:42:03
Go to the top of the page
+Quote Post
Neutral
post 12.10.2017, 20:44:46
Post #2





Grupa: Zarejestrowani
Postów: 286
Pomógł: 46
Dołączył: 10.01.2016

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


Nie za bardzo rozumiem w czym masz problem. Może zmień na fetch_assoc? Szukasz użytkowników z ich preferencjami, danymi z bazy; tak? Jeśli np. w formularzu zaznaczyłeś checkbox'y o ile masz, wpisałeś jakich ma danych szukać, to tylko musisz dać odpowiedni warunek w kodzie, po stronie back-end'u.

Na czas testów powyrzucaj wszystkie empty, isset, null'e, redirect'y, itp., ponieważ przez to najprawdopodobniej Ci się dane nie wyświetlają.

Ten post edytował Neutral 12.10.2017, 20:59:36
Go to the top of the page
+Quote Post
buddha
post 13.10.2017, 07:55:36
Post #3





Grupa: Zarejestrowani
Postów: 23
Pomógł: 0
Dołączył: 7.09.2017

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


Zmienić na fetch_assoc?
Tak, szukam użytkowników przez preferencje z bazy

Mój cały kod strony z wyszukiwaniem wygląda tak
( wszystko działa, lecz niestety tylko gdy jestem zalogowany )

  1. <?php $e_age = explode( ',', $sm['user']['s_age'] ); $age = $e_age[2]; $age2 = $e_age[1]; $age1 = $e_age[0]; ?>
  2. <script>
  3. url = "search";
  4. </script>
  5. <div class="search-people-container" style="display:none">
  6. <div class="container relative search-people">
  7. <div class="search-text"> </div>
  8. <div class="search-form" style="display:none;">
  9. <h2 class="show-me"><?= $sm['lang'][109]['text']; ?></h2>
  10. <input type="hidden" value="0" id="meet_filter_limit" data-filter="meet_filter_limit" />
  11. <select class="select1" data-filter="meet_filter_gender" id="meet_filter_gender">
  12. <option value="2" <?php if($sm[ 'user'][ 's_gender']==2 ) { echo 'selected'; } ?>>
  13. <?= $sm['lang'][110]['text']; ?>
  14. </option>
  15. <option value="1" <?php if($sm[ 'user'][ 's_gender']==1 ) { echo 'selected'; } ?>>
  16. <?= $sm['lang'][111]['text']; ?>
  17. </option>
  18. <option value="3" <?php if($sm[ 'user'][ 's_gender']==3 ) { echo 'selected'; } ?>>
  19. <?= $sm['lang'][112]['text']; ?>
  20. </option>
  21. </select>
  22. <input class="select2" style="width: 115px;" value="<?= $age1;?>" type="number" min="18" max="99" data-filter="meet_filter_age1" id="meet_filter_age1" />
  23. <input class="select2" style="width: 115px;left:550px;" value="<?= $age2;?>" type="number" min="18" max="99" data-filter="meet_filter_age2" id="meet_filter_age2"/>
  24.  
  25. <input class="input" type="text" id="meet_filter_city" value="<?= $sm['user']['city']; ?>" />
  26. <div class="input-location"><i class="material-icons">location_on</i></div>
  27. <select class="select3" data-filter="meet_filter_radius" id="meet_filter_radius">
  28. <option value="300" <?php if($sm[ 'user'][ 's_radius']==100) { echo 'selected'; } ?>>All the city</option>
  29. <option value="10000000" <?php if($sm[ 'user'][ 's_radius']==1000) { echo 'selected'; } ?>>
  30. <?= $sm['twoo_lang'][6]['text']; ?>
  31. </option>
  32. </select>
  33. <select class="select4" id="meet_filter_online" data-filter="meet_filter_online">
  34. <option value="0" selected>
  35. <?= $sm['twoo_lang'][9]['text']; ?>
  36. </option>
  37. <option value="1">
  38. <?= $sm['twoo_lang'][10]['text']; ?>
  39. </option>
  40. </select>
  41. <h2 class="show-me-more"><?= $sm['lang'][109]['text']; ?></h2>
  42. </div>
  43. </div>
  44. </div>
  45. <div class="search-result-container">
  46.  
  47. <div class="container relative margin-bottom-50">
  48.  
  49. <div class="search-section">
  50. <div id="searching">
  51. <div class="pulse"></div>
  52. <div class="pulse-photo" data-back-photo="1" data-src="<?= $sm['user']['profile_photo']; ?>"></div>
  53. </div>
  54. <div id="meet_section"> </div>
  55. </div>
  56. </div>
  57. <div class="rings" style="display:none">
  58. <div class="user-photo" data-back-photo="1" data-src="<?= $sm['user']['profile_photo']; ?>"></div>
  59. <div class="ring__ringlet"></div>
  60. <div class="ring__ringlet"></div>
  61. <div class="ring__ringlet"></div>
  62. </div>
  63. </div>


Ten post edytował buddha 13.10.2017, 07:56:43
Go to the top of the page
+Quote Post
Neutral
post 13.10.2017, 10:04:13
Post #4





Grupa: Zarejestrowani
Postów: 286
Pomógł: 46
Dołączył: 10.01.2016

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


Skoro masz poustawiane warunki, że tylko zalogowani mogą filtrować dane, to jaki problem je usunąć?

  1. if (!empty($_SESSION['user']) && is_numeric($_SESSION['user']) && $_SESSION['user'] > 0) {


To oznacza:
Jeśli sesja o nazwie 'user' nie jest pusta i jest ona wartością numeryczną oraz, gdy ta wartość jest większa od zera; wykonaj kod pod spodem.

  1. if($_GET['id'] != NULL ){

Gdy zmienna $_GET['id'] nie jest równa NULL, wykonaj kod.

Musisz zobaczyć te warunki w kodzie i je wszystkie bądź część wyrzucić i sprawdzić, czy pójdzie.

Ten post edytował Neutral 13.10.2017, 10:05:10
Go to the top of the page
+Quote Post
nospor
post 13.10.2017, 10:13:13
Post #5





Grupa: Moderatorzy
Postów: 36 440
Pomógł: 6290
Dołączył: 27.12.2004




@Neutral chyba troche za bardzo odplynales... Ok, na pewno on tam ma gdzies sprawdzanie czy user zalogowany czy nie, i trzeba to znalezc i sprawdzic, ale wywalanie kluczowego IFa z funkcji islogged to chyba lekka przesada... Jak juz cos to wywalic trzeba funkcje isLogged gdzies tam w jakims warunku a nie jej srodek.

Podobnie z if($_GET['id'] != NULL ){
Przeciez to jest w funkcji, ktora pobiera dane o jakims tam userze, a info o tym userze jest w GET. Wywalajac warunek na to, to on bedzie lecial do bazy nawet jak ID w GET nie bedzie istnialo...

Jak juz pomagasz to pomysl wpierw sam troche a nie lecisz na oslep

ps: o zamianie fetch_object na fetch_assoc to juz nawet nie bede wspominal... niby jak to ma rozwiazac problem?


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
buddha
post 13.10.2017, 11:03:27
Post #6





Grupa: Zarejestrowani
Postów: 23
Pomógł: 0
Dołączył: 7.09.2017

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


@Neutral spróbowałem jak napisałeś. lecz pomimo tego dalej nie mam dostępu.

@nospor. próbowałem usunąć całą funkcje isLogged - niestety nic nie daje.. też spróbowałem
jak napisałeś ( usunąłem if($_GET['id'] != NULL ) ) ale brak tego wywołuje jedynie funkcje
na przeglądanym profilu tak jakbyśmy przeglądali własny profil
( odtwarzają nam się ikony, przyciski itd jak by to było nasze konto )



Go to the top of the page
+Quote Post
nospor
post 13.10.2017, 11:05:44
Post #7





Grupa: Moderatorzy
Postów: 36 440
Pomógł: 6290
Dołączył: 27.12.2004




Cytat
jak napisałeś ( usunąłem if($_GET['id'] != NULL ) )
Nigdzie nie pisalem ze masz tu usuwac. To neutral takie rzeczy ci pisal.

Cytat
próbowałem usunąć całą funkcje isLogged - niestety nic nie daje.
Nie kazalem tez ci usuwac funkcji isLogged()... Mowilem ze masz znalezc miejsca gdzie ta funkcja jest uzyta i tam kombinowac. Z jakiegos powodu ktos dal wyszukiwanie tylko dla zalogowanych. Trzeba to miejsce znalezc


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
buddha
post 13.10.2017, 11:30:42
Post #8





Grupa: Zarejestrowani
Postów: 23
Pomógł: 0
Dołączył: 7.09.2017

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


@nospor wybacz, jestem strasznie narwany. Borykam się z tym problem ponad tydzień.

Znalazłem w tym samym pliku też taką funkcje

  1. function searchUser($q) {
  2.  
  3. global $mysqli,$sm;
  4.  
  5. $search = '';
  6.  
  7. $query = $mysqli->query("SELECT id FROM users where id = '".$q."' OR name LIKE '%$q%' OR email LIKE '%$q%' LIMIT 10");
  8.  
  9.  
  10.  
  11. if ($query->num_rows > 0) {
  12.  
  13. while($user = $query->fetch_object()){
  14.  
  15. getUserInfo($user->id,6);
  16.  
  17. $search .= ' <tr>
  18.  
  19. <td class="man-photos"><div class="profile-photo" data-src="'.$sm['search']['profile_photo'].'"></td>
  20.  
  21. <td>'.$sm['search']['id'].'</td>
  22.  
  23. <td>'.$sm['search']['name'].' , '.$sm['search']['age'].'
  24.  
  25. '; if($sm['search']['last_access'] >= $time_now) {
  26.  
  27. $search .= ' <i class="fa fa-circle text-success" style="font-size:8px;"></i>';
  28.  
  29. }
  30.  
  31.  
  32.  
  33. $search .= '
  34.  
  35. </td>
  36.  
  37. <td>'.$sm['search']['email'].'</td>
  38.  
  39. <td>'.$sm['search']['city'].'</td>
  40.  
  41. <td>'.$sm['search']['country'].'</td>
  42.  
  43. <td>'.$sm['search']['credits'].'</td>
  44.  
  45. <td>'.$sm['search']['total_photos'].'</td>
  46.  
  47. <td>'.$sm['search']['join_date'].'</td>
  48.  
  49. <td><a href="index.php?page=profile&id='.$sm['search']['id'].'" target="_blank" class="label label-info">View</a>
  50.  
  51. <a href="index.php?page=admin&p=user&id='.$sm['search']['id'].'" target="_blank" class="label label-primary">Edit</a></td>
  52.  
  53. </tr>';
  54.  
  55. }
  56.  
  57. }
  58.  
  59. return $search;
  60.  
  61. }


i znalazłem też

  1. function getUserInfo($uid,$value=0) {
  2.  
  3. global $mysqli,$sm;
  4.  
  5.  
  6.  
  7. $uid = secureEncode($uid);
  8.  
  9. $user = $mysqli->query("SELECT * FROM users WHERE id = '".$uid."'");
  10.  
  11. $u = $user->fetch_object();
  12.  
  13. $first_name = explode(' ',trim($u->name));
  14.  
  15. $first_name = explode('_',trim($first_name[0]));
  16.  
  17. //CURRENT USER
  18.  
  19. $current_user['id'] = $u->id;
  20.  
  21. $current_user['name'] = $u->name;
  22.  
  23. $current_user['email'] = $u->email;
  24.  
  25. $current_user['gender'] = $u->gender;
  26.  
  27. $current_user['facebook_id'] = $u->facebook_id;
  28.  
  29. $current_user['twitter_id'] = $u->twitter_id;
  30.  
  31. $current_user['google_id'] = $u->google_id;
  32.  
  33. $current_user['instagram_id'] = $u->instagram_id;
  34.  
  35. $current_user['first_name'] = $first_name[0];
  36.  
  37. $current_user['profile_photo'] = profilePhoto($u->id);
  38.  
  39. $current_user['profile_photo_thumb'] = profilePhotoThumb($u->id);
  40.  
  41. $current_user['total_photos'] = getUserTotalPhotos($u->id);
  42.  
  43. $current_user['total_photos_public'] = getUserTotalPhotosPublic($u->id);
  44.  
  45. $current_user['total_photos_private'] = getUserTotalPhotosPrivate($u->id);
  46.  
  47. $current_user['total_likers'] = getUserTotalLikers($u->id);
  48.  
  49. $current_user['total_likes'] = getUserTotalLikes($u->id);
  50.  
  51. $current_user['extended'] = userExtended($u->id);
  52.  
  53. $current_user['interest'] = userInterest($u->id);
  54.  
  55. $current_user['status_info'] = userFilterStatus($u->id);
  56.  
  57. //$current_user['status'] = userStatus($u->id);
  58.  
  59. $current_user['city'] = $u->city;
  60.  
  61. $current_user['country'] = $u->country;
  62.  
  63. $current_user['age'] = $u->age;
  64.  
  65. $current_user['lat'] = $u->lat;
  66.  
  67. $current_user['lng'] = $u->lng;
  68.  
  69. $current_user['birthday'] = $u->birthday;
  70.  
  71. $current_user['last_access'] = $u->last_access;
  72.  
  73. $current_user['admin'] = $u->admin;
  74.  
  75. $current_user['lang'] = $u->lang;
  76.  
  77. $current_user['looking'] = $u->looking;
  78.  
  79. $current_user['premium'] = $u->premium;
  80.  
  81. $current_user['premium_check'] = adminCheckUserPremium($uid);
  82.  
  83. $current_user['verified'] = $u->verified;
  84.  
  85. $current_user['popular'] = $u->popular;
  86.  
  87. $current_user['credits'] = $u->credits;
  88.  
  89. $current_user['link'] = clean($first_name[0]);
  90.  
  91. $current_user['status'] = userStatus($u->id);
  92.  
  93. $current_user['online'] = userStatusIcon($u->id);
  94.  
  95. $current_user['fake'] = $u->fake;
  96.  
  97. $current_user['join_date'] = $u->join_date;
  98.  
  99. $current_user['bio'] = $u->bio;
  100.  
  101. $current_user['s_gender'] = $u->s_gender;
  102.  
  103. $current_user['s_radius'] = $u->s_radious;
  104.  
  105. $current_user['s_age'] = $u->s_age;
  106.  
  107. $current_user['online_day'] = $u->online_day;
  108.  
  109. if($value == 1){
  110.  
  111. $sm['profile'] = $current_user;
  112.  
  113. } else if($value == 2){
  114.  
  115. $sm['meet'] = $current_user;
  116.  
  117. } else if($value == 3){
  118.  
  119. $sm['chat'] = $current_user;
  120.  
  121. } else if($value == 4){
  122.  
  123. $sm['friend'] = $current_user;
  124.  
  125. } else if($value == 5){
  126.  
  127. $sm['videocall'] = $current_user;
  128.  
  129. } else if($value == 6){
  130.  
  131. $sm['search'] = $current_user;
  132.  
  133. } else if($value == 7){
  134.  
  135. $sm['manage'] = $current_user;
  136.  
  137. } else if($value == 8){
  138.  
  139. $sm['edit'] = $current_user;
  140.  
  141. } else if($value == 9){
  142.  
  143. $sm['comment'] = $current_user;
  144.  
  145. } else if($value == 10){
  146.  
  147. $sm['suggest'] = $current_user;
  148.  
  149. } else if($value == 11){
  150.  
  151. $sm['gift'] = $current_user;
  152.  
  153. } else if($value == 12){
  154.  
  155. $sm['mail'] = $current_user;
  156.  
  157. } else{
  158.  
  159. $sm['user'] = $current_user;
  160.  
  161. }
  162.  
  163. }



  1. function getUserPhotos($uid,$i=0,$x=0,$y=0,$b=0){
  2.  
  3. global $mysqli,$sm;
  4.  
  5. $photo = "";
  6.  
  7. if($i == 1){
  8.  
  9. $photos = $mysqli->query("SELECT * FROM users_photos WHERE u_id = '".$uid."' and approved = 1 order by id desc LIMIT 200");
  10.  
  11. } else if($b == 1){
  12.  
  13. $photos = $mysqli->query("SELECT * FROM users_photos WHERE approved = 1 and u_id = '".$uid."' and blocked = 1 order by id desc LIMIT 200");
  14.  
  15. } else {
  16.  
  17. $photos = $mysqli->query("SELECT * FROM users_photos WHERE approved = 1 and u_id = '".$uid."' and blocked = 0 order by id desc LIMIT 200");
  18.  
  19. }
  20.  
  21. if ($photos->num_rows > 0) {
  22.  
  23. while($up = $photos->fetch_object()){
  24.  
  25. getUserInfo($uid,1);
  26.  
  27. $photoData['id'] = $up->id;
  28.  
  29. $photoData['src'] = $up->photo;
  30.  
  31. $photoData['desc'] = $up->desc;
  32.  
  33. $photoData['user'] = $sm['profile']['name'];
  34.  
  35. $photoData['photo'] = $sm['profile']['profile_photo'];
  36.  
  37. $photoData['blocked'] = $up->blocked;
  38.  
  39. $photoData['like'] = checkPhotoLike($sm['user']['id'],$up->id);
  40.  
  41. $photoData['likes'] = getPhotoLikes($up->id);
  42.  
  43. $photoData['comments'] = getPhotoComments($up->id);
  44.  
  45. $sm['photo'] = $photoData;
  46.  
  47. if($i == 1 && $x == 0){
  48.  
  49. $photo .= getPage('profile/mphoto');
  50.  
  51. } else if($x == 1){
  52.  
  53. $photo .= requestPage('profile/mphoto');
  54.  
  55. } else {
  56.  
  57. $photo .= requestPage('profile/photo');
  58.  
  59. }
  60.  
  61. }
  62.  
  63. }
  64.  
  65. return $photo;
  66.  
  67. }

Go to the top of the page
+Quote Post
nospor
post 13.10.2017, 11:59:58
Post #9





Grupa: Moderatorzy
Postów: 36 440
Pomógł: 6290
Dołączył: 27.12.2004




Zadan z tych funkcji ma sie nijak do zalogowania lub nie.

Swoja droga nie wiem kto to ci pisal, ale mial nie wieksza wiedzie od ciebie teraz.


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
viking
post 13.10.2017, 12:03:13
Post #10





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

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


Z tego co pamiętam pisał wcześniej że to jakiś tam pobrany skrypt który chce przerobić usuwając logowanie. Tylko widać że wiedza nie jest adekwatna do złożoności zadania.


--------------------
Go to the top of the page
+Quote Post
buddha
post 13.10.2017, 12:17:22
Post #11





Grupa: Zarejestrowani
Postów: 23
Pomógł: 0
Dołączył: 7.09.2017

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


Macie racje, jestem kompletnie zielony.
Sam już nie mam pojęcia jak mógłbym uzyskać ten efekt o który tak ubiegam :/



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: 28.03.2024 - 16:02