Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [Pomoc] Edycja użytkownika
menhils
post
Post #1





Grupa: Zarejestrowani
Postów: 32
Pomógł: 0
Dołączył: 6.01.2012

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


Problem polega na tym, że jak zaloguje się na konto admina, wejdę do PA i zmienia hasło użytkownika test i klikam ok to zostaje zalogowany na konto użytkownika test z uprawnieniami admina


u_view.adm.php
  1. <?php
  2. include('config.php');
  3. function escape($data){
  4.  
  5. GLOBAL $dbc;
  6. if (ini_get('magic_quotes_gpc')){
  7. $data = stripslashes($data);
  8. }
  9. return mysql_real_escape_string($data, $dbc);
  10. }
  11. function view_user(){
  12. GLOBAL $dbc, $id;
  13.  
  14. $query="SELECT * FROM user";
  15. $result= @mysql_query($query);
  16.  
  17. echo '<Br /> <br />';
  18. echo'<table align="center" border="0">
  19. <tr>
  20. <td align="left" width="20">Np.</td>
  21. <td width="100">Login</td>
  22. <td width="100">Data rejstracji</td>
  23. </tr>';
  24.  
  25. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
  26.  
  27. echo "<tr>
  28. <td align=\"left\" width=\"20\">{$row['user_id']}</td>
  29. <td><a href=\"mailto:{$row['email']}\">{$row['username']}</a></td>
  30. <td>{$row['data_rejstacji']}</td>
  31. <td width=\"100\" align=\"center\"><a href=\"u_view.php?cmd=edit&id={$row['user_id']}\">edytuj</a> :: <a href=\"u_view.php?cmd=del&id={$row['user_id']}\">usun</a></td>
  32. </tr>";
  33.  
  34. }
  35. echo '</table>';
  36. }
  37. function edit_form(){
  38. GLOBAL $dbc, $username, $password, $email, $id, $PHP_SELF;
  39.  
  40. $query="SELECT * FROM user WHERE user_id='{$_GET['id']}'";
  41. $result= @mysql_query($query);
  42. $row = mysql_fetch_array($result, MYSQL_ASSOC);
  43.  
  44. echo '<form method="post" action="'.$_SERVER['PHP_SELF'].'?cmd=update&id='.$_GET['id'].'">
  45. <table align="center" border="0">
  46. <tr>
  47. <td align="right">username:</td>
  48. <td><input type="text" name="username" value="'.$row['username'].'" size="30">
  49. </td>
  50. </tr>
  51. <tr>
  52. <td align="right">email:</td>
  53. <td><input type="text" name="email" value="'.$row['email'].'" size="30">
  54. </td>
  55. </tr>
  56. <tr>
  57. <td align="right">password:</td>
  58. <td><input type="password" name="password" "size="30">
  59. </td>
  60. </tr>
  61. <tr>
  62. <td align="right"> </td>
  63. <td><input style="font-weight: bold;" type="submit" name="submit" value="Zmien">
  64. <input type="reset" name="Reset" value="wyczyść">
  65. </td></tr>
  66. </table>
  67. </form>';
  68.  
  69. }
  70. function update(){
  71. GLOBAL $dbc, $username, $email, $password, $id;
  72.  
  73. $username = escape($_POST['username']);
  74. $email = escape($_POST['email']);
  75.  
  76. if (isset($_POST['password'])){
  77. $query = "UPDATE user SET username='$username', email='$email', haslo=PASSWORD('{$_POST['password']}') WHERE user_id='{$_GET['id']}'";
  78. }else{
  79. $query = "UPDATE user SET username='$username', email='$email'WHERE user_id='{$_GET['id']}'";
  80. }
  81. $result=mysql_query($query);
  82.  
  83. echo 'Dane zostały zmienione<Br />';
  84. echo '<a href="admin.php?cmd=ok">Strona głowna</a>';
  85. }
  86. ?>
Go to the top of the page
+Quote Post
marins
post
Post #2





Grupa: Zarejestrowani
Postów: 47
Pomógł: 4
Dołączył: 12.07.2003

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


Jesteś pewny, że problem leży w załączonym kodzie? po przyglądnięciu się mogę stwierdzić, że ten kod jest ok.
Go to the top of the page
+Quote Post
menhils
post
Post #3





Grupa: Zarejestrowani
Postów: 32
Pomógł: 0
Dołączył: 6.01.2012

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


Te kody są ok. tylko czegoś brakuje że podczas edycji innego użytkownika loguje się na jego konto

Tutaj mam panel logowania.php

  1. <?
  2. require_once('./config1.php'); // załaczamy plik config.php
  3.  
  4. function usun($data){
  5.  
  6. GLOBAL $dbc;
  7. if (ini_get('magic_quotes_gpc')){
  8. $data = stripslashes($data);
  9. }
  10. return mysql_real_escape_string($data, $dbc);
  11. }
  12.  
  13. if (isset($_POST['submit'])){
  14.  
  15. if (empty($_POST['login'])){
  16. $message .= '<font color="red" class="blad">Nie podałeś loginu</font><br />';
  17. $l = FALSE;
  18. }else{
  19. $l = usun($_POST['login']);
  20. }
  21.  
  22. if (empty($_POST['haslo'])){
  23. $message .= '<font color="red" class="blad">Nie podałeś hasła</font><br />';
  24. $h = FALSE;
  25. }else{
  26. $h = usun($_POST['haslo']);
  27. }
  28.  
  29. if ( $l && $h ){
  30.  
  31. $query = "SELECT username, access FROM user WHERE username='$l' AND haslo=password('$h')";
  32. $result = mysql_query($query);
  33. $row = mysql_fetch_array ($result, MYSQL_ASSOC);
  34.  
  35. if($row){
  36.  
  37. $_SESSION['username'] = $row['username'];
  38. $_SESSION['access'] = $row['access'];
  39. $_GET['cmd'] = 'start';
  40. echo 'Zalogowałeś się<meta http-equiv="refresh" content="1; URL=index.php?id=start"><br>';
  41.  
  42. }else{
  43. $message .= '<font color="red" class="blad">Błędne hasło lub login</font><br />';
  44. }
  45. }else{
  46. $message .= '<font color="red" class="blad">Spróbuj jeszcze raz</font>';
  47. }
  48. }
  49. ?>
  50. <?php
  51. if ($_SESSION['username']!=''){
  52. echo 'Witaj <b>'.$_SESSION['username'].'</b>!<br><br><a href="wyloguj.php"><img src="images/wyloguj.png"/></a><br>';
  53. }
  54. else {
  55. echo '
  56.  
  57. <form method="post" action="index.php?id=start">
  58. <table border="0">
  59. <tr>
  60.  
  61. <td>Login:<input type="text" name="login" size="30"></td>
  62. </tr>
  63.  
  64. <tr>
  65.  
  66. <td>Password:<input type="password" name="haslo" size="30"></td>
  67. </tr>
  68. <tr>
  69. <td class="uni_01"></td>
  70. <td>
  71. <p style="margin-left:-207px;"><input style="font-weight: bold;" type="submit" name="submit" value="Zaloguj">
  72. </td></tr>
  73. </table>
  74. </form>
  75.  
  76. Nie jesteś zalogowany<br> <a href="rejestracja.php"><img src="images/rejestracja.png"/></a>';
  77. }
  78. ?>
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: 14.09.2025 - 17:50