Exibindo resultados 1 até 2 de 2

Tópico: Logar-se automaticamente - PHP

  1. #1
    Desde
    Jun 2004
    Posts
    1
    Peso da Avaliação
    0

    Logar-se automaticamente - PHP

    EAe galera! Esse é o meu primeiro post, espero que possam me ajudar :)

    Como fazer um programa para logar-se num site automaticamente? O site é em PHP e pede-se apenas nome de usuário e senha. Li algo sobre, mas era em ASP e n entendi mto bem...
    Qualquer coisa o site é http://www.lapafest.com.br

    Obrigado!

  2. #2
    Desde
    Oct 2001
    Posts
    4.484
    Peso da Avaliação
    26

    Re: Logar-se automaticamente - PHP

    Cookies.

    Código PHP:
    <?php
    // ----------------------------------------------------------------------------------------
    // topic:     Track login vars and session_id with cookies and allow autologin
    // author:    Copyright (c) by Urs Gehrig <admin@circle.ch>
    // version:   1.0.0
    // update:    26-7-2000
    // PHP:       php-4.0.0-win32
    //
    // handling:  use this function to ask for a login for first time visitors and track their
    //            login/password information in cookies on the client's side. you will still
    //            need to inform the user about enabling cookies. further, there is only a
    //            a check of login/password against the contents of the cookie, once it is set
    //            for longer than just the session.
    //
    // Passwords: your_passwords.txt
    //            your_login,your_password
    //            my_login,my_password
    //
    // Browser:   It has been tested and it worked with IE5
    //
    // Enjoy!
    // ----------------------------------------------------------------------------------------


    // ----------------------------------------------------------------------------------------
    // functions
    // ----------------------------------------------------------------------------------------

          
    function LoginForm(){
                global 
    $PHP_SELF;

                
    $header '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD><TITLE>login form</TITLE></HEAD><BODY>';
                
    $footer '</BODY></HTML>';

                echo 
    $header;

                
    ?>
                <form method="post" action="<?php echo basename($PHP_SELF); ?>" name=loginform>
                <table frame=void rules=none WIDTH="300">

                <tr>
                  <td align="left">
                  login:
                  <td align="left">
                  <input type="text" name="login" maxlength=50 size=15 style="width: 120px; font-size: 12px">
                <tr>
                  <td align="left">
                  password:
                  <td align="left">
                  <input type="password" name="passwd" maxlength=50 size=15 style="width: 120px; font-size: 12px">
                <tr>
                  <td align="left">&nbsp;
                  <td align="left">&nbsp;
                <tr>
                  <td align="left">
                  &nbsp;
                  <td align="left">
                  <input type=submit value="login" name="sent" style="width: 50px; heigth: 18px; font-size: 12px">
                </table>
                </form>

                <script type="text/javascript">
                <!--
                if (document.loginform) {
                   document.loginform.login.focus();
                }
                // -->
                </script>
              <?php

              
    echo $footer;
          }

          function 
    getItem($item,$str){
            
    $pairs explode("&"$str);

            for(
    $i=0;$i<count($pairs);$i++):
              
    $query[$i] = explode("="$pairs[$i]);
              if(
    $query[$i][0] == $item):
                return 
    $query[$i][1];
                break;
              endif;
            endfor;
          }

          function 
    cke_auth(){
              global 
    $PHP_SELF$sent$ID$mysession$login$passwd;
              
    // you may select a cookielifetime
              
    $cke_days 1;
              
    $cke_secs $cke_days 24 3600;              // cookie lifetime in seconds (e.g. here: 1 day)
              
    $cke_time time()+ $cke_secs;

              
    //$cke_time = 0;                                  // my cookielifetime is lasting the session
              
    if(isset($sent)):                               // from login form
                
    $login_ok 0;
                if (isset(
    $login) and isset($passwd)):
                  
    $fp fopen("your_passwords.txt""r");

                  while (
    feof($fp) == 0):
                    
    $line chop(fgets($fp,1000));
                    
    $arr explode(","$line);
                    if ((
    $arr[0] == $login) and ($arr[1] == $passwd)):
                      
    session_start();
                      
    setcookie("login"$login$cke_time);
                      
    setcookie("passwd"$passwd$cke_time);
                      
    setcookie("ID"session_id(), $cke_time);
                      return 
    1;                               // authentication succeeded
                      
    $login_ok 1;
                      break;
                    endif;
                  endwhile;
                endif;
                if(!
    $login_ok):
                  return 
    0;                                   // access denied
                
    endif;

              else:
                
    $fp fopen("your_passwords.txt""r");
                while (
    feof($fp) == 0):
                  
    $line chop(fgets($fp,1000));
                  
    $arr explode(","$line);
                  if ((
    $arr[0] == $login) AND ($arr[1] == $passwd)):
                    return 
    1;                                 // authentication succeeded
                    
    $login_ok 1;
                    break;
                  endif;
                endwhile;
                if(!
    $login_ok):
                  return 
    0;                                   // access denied
                
    endif;
              endif;
          }

    // ----------------------------------------------------------------------------------------
    // main
    // ----------------------------------------------------------------------------------------

          //init vars;
          
    $uri basename($PHP_SELF);
          
    $stamp md5(srand(5));

          if(!
    cke_auth()):             // authentication failed
              
    LoginForm();             // display login form

          
    else:                        // authentication was successful
            //header ("Location: wherever.com");

            
    if (isset($sent)):
              echo 
    "logged in from <b>login form</b><br><br>";
              echo 
    "Your login name: <b>".$login."</b><br>";
              echo 
    "Your password:   <b>".$passwd."</b><br>";
              echo 
    "<br><br><br><a href='$uri?SID=$ID'>load</a>";
           else:
              echo 
    "logged in from <b>cookie:</b> ".$ID."<br>";
              echo 
    "changing <b>stamp:</b> $stamp<br><br>";
              echo 
    "Your login name: <b>".$login."</b><br>";
              echo 
    "Your password:   <b>".$passwd."</b><br>";
              echo 
    "<br><br><br><a href='$uri?SID=$ID&stamp=$stamp'>load</a>";
            endif;
          endif;

    ?>
    Do original: http://www.zend.com/codex.php?id=242&single=1

    []s, MM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tópicos semelhantes

  1. CAIS-Alerta: Multiplas vulnerabilidades no PHP 4.3.9 e 5.0.2
    By psergiom in forum Desenvolvimento seguro
    Respostas: 1
    Último post: 22/12/2004, 14:28
  2. Novo tipo de scam rouba dados automaticamente
    By ruicruz in forum Notícias de segurança
    Respostas: 0
    Último post: 04/11/2004, 18:45
  3. Vul em php
    By @prendiz in forum Penetration Tests
    Respostas: 8
    Último post: 01/10/2003, 10:35
  4. Divulgada nova falha no PHP
    By mmachado in forum Notícias de segurança
    Respostas: 0
    Último post: 23/07/2002, 11:43
  5. Falha em php.
    By Number One in forum Notícias de segurança
    Respostas: 2
    Último post: 19/03/2002, 20:33

Regras de envio

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •