Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP][MYSQL]Problem ze skryptem logowania
tadek92
post
Post #1





Grupa: Zarejestrowani
Postów: 108
Pomógł: 3
Dołączył: 26.07.2008

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


Witam!
Piszę właśnie skrypt logowania się użytkowników. Mam z nim pewien problem. Mianowicie, niezależnie od tego jakiego użytkownika chcę zalogować loguje się zawsze jeden i ten sam pierwszy użytkownik w bazie danych. Zupełnie nie mogę sobie poradzić z tym skryptem. Proszę o pomoc.
Kod
<?php
  if (isset($_POST['user_email']) and isset($_POST['user_password']) )
  
  {
  
  include("config.php");
      @mysql_connect ("$mysql_host", "$mysql_user", "$mysql_password") or
      die ("Nie można połączyć się z MySQL");
      @mysql_select_db ("$mysql_db") or
      die ("Nie można połączyć się z bazą $mysql_db");
      mysql_query("SET NAMES 'utf8'");
  
  $email=mysql_real_escape_string(trim($_POST['user_email']));
  
  $password=mysql_real_escape_string(trim($_POST['user_password']));
  
  if ($email!="" and $password!="")
  
  {
  
     $password = sha1(md5($password));
  
     $query="SELECT * FROM users WHERE user_email='$email' and user_password ='$password'";
  
     $temp=mysql_query($query) or die("<strong>Wystąpił błąd</strong>");
  
      $num=mysql_num_rows($temp);
  
     $temp=mysql_fetch_array($temp);
  
     $id=$temp['id'];
      
  
  
     if ($num==1)
  
     {
    
    $result = mysql_query ("SELECT * FROM users WHERE user_email='$email' and user_password ='$password'");
          if ($result && $record = mysql_fetch_assoc ($result))
          {
              foreach($record as $key => &$value) {$value = stripslashes($value);}
              $user_active = $record['user_active'];
              $user_email = $record['user_email'];
              $user_id = $record['user_id'];
              
          }
      
  if ($user_active == 0)
     {
     session_start();
     $_SESSION['sesja']="ok";
      $_SESSION['user_email'] = $user_email;
     $_SESSION['user_id'] = $user_id;
     header('Location: index.php?panel=ok');
            
      }
      else {
      echo"<strong>Błąd logowania!</strong><p>Nie jesteś aktywowany!
  Odbierz maila z linkiem aktywacyjnym.</p>";
      }
  
     }
  
     else echo ('<strong>Błąd logowania!</strong><p>Podales złe dane!
  Spróbuj zalogować się ponownie.</p>');
  
  }
  
  }
  
  else{
  
  ?>
  <form action="#" method="post">
  <fieldset>
  <div class="divform"><label>E-mail:</label> <input name="user_email" type="text" value="" /></div>
  <div class="divform"><label>Hasło:</label> <input name="user_password" type="password" value="" /></div>  
  <div class="divform"><label><?php echo "<a href=\"http://$domain/index.php?register=ok\">Zarejestruj się</a>"; ?></label><input type="submit" value="Zaloguj się" /></div>  
  </fieldset>
  </form>
  <?php
  
  }?>


Poradziłem już sobie z tym problemem. Mam jednak jeszcze jeden problem jak ustawić jedną sesję dla wszystkich subdomen?

Ten post edytował tadek92 22.05.2009, 18:02:57
Go to the top of the page
+Quote Post

Posty w temacie


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 Aktualny czas: 20.08.2025 - 04:42