Foros del Web » Programando para Internet » PHP »

Login

Estas en el tema de Login en el foro de PHP en Foros del Web. Hola, buen dia Encontre dos ejemplos, para phpbb Login Ejemplo 1 Código: <? /* * PHPBB_Login allows you to integrate your own login system * ...
  #1 (permalink)  
Antiguo 19/06/2005, 09:11
 
Fecha de Ingreso: agosto-2004
Mensajes: 51
Antigüedad: 19 años, 7 meses
Puntos: 0
Login

Hola, buen dia

Encontre dos ejemplos, para phpbb Login

Ejemplo 1

Código:
<?

/*
 * PHPBB_Login allows you to integrate your own login system
 * with phpBB. Meaning that you can have one login valid across
 * both your website and phpBB.
 *
 * To take full advantage of this PHPBB_Login class you just
 * need to modify your own login system to include a call
 * to the relevant methods in here.
 *
 * This system is reliant on the website username being exactly
 * the same as the phpBB username. To insure this, I recommend
 * disabling the ability to change usernames from within the 
 * phpBB admin control panel.
 *

 */

class PHPBB_Login {

    function PHPBB_Login() {
    }

    function login( $phpbb_user_id ) {
        global $db, $board_config;
        global $HTTP_COOKIE_VARS, $HTTP_GET_VARS, $SID;
    
        // Setup the phpbb environment and then
        // run through the phpbb login process

        // You may need to change the following line to reflect
        // your phpBB installation.
        require_once( './forum/config.php' );
    
        define('IN_PHPBB',true);

        // You may need to change the following line to reflect
        // your phpBB installation.
        $phpbb_root_path = "./forum/";
        
        require_once( $phpbb_root_path . "extension.inc" );
        require_once( $phpbb_root_path . "common.php" );

        return session_begin( $phpbb_user_id, $user_ip, PAGE_INDEX, FALSE, TRUE );
    
    }

    function logout( $session_id, $phpbb_user_id ) {
        global $db, $lang, $board_config;
        global $HTTP_COOKIE_VARS, $HTTP_GET_VARS, $SID;
    
        // Setup the phpbb environment and then
        // run through the phpbb login process

        // You may need to change the following line to reflect
        // your phpBB installation.
        require_once( './forum/config.php' );
    
        define('IN_PHPBB',true);
        
        // You may need to change the following line to reflect
        // your phpBB installation.
        $phpbb_root_path = "./forum/";

        require_once( $phpbb_root_path . "extension.inc" );
        require_once( $phpbb_root_path . "common.php" );

        session_end( $session_id, $phpbb_user_id );
    
        // session_end doesn't seem to get rid of these cookies,
        // so we'll do it here just in to make certain.
        setcookie( $board_config[ "cookie_name" ] . "_sid", "", time() - 3600, " " );
        setcookie( $board_config[ "cookie_name" ] . "_mysql", "", time() - 3600, " " );

    }

}

?>
Para la session

Código:
<?

/*
 * These examples show you how to integrate the phpBB
 * login in and authentication system with your website.
 * 
 * Since we quite like our login system and it's proven
 * itself to be very extensible, we don't want to replace
 * but we do want to have a universal login system for
 * both our website *and* the forum.
 *
 * To take full advantage of this PHPBB_Login class you'll
 * need to modify your own login system to include a call
 * to the relevant login or logout methods.
 *
 * This way, you can handle all of the website login as normal,
 * and also log the user into phpBB in the same step.
 *
 * This system is reliant on the website username being exactly
 * the same as the phpBB username. To insure this, I recommend
 * disabling the ability to change usernames from within the 
 * phpBB admin control panel.
 *
 */




/*  Logging in */

session_start();

/* First, login the user using your own login system, for example; */
$user = new User();

// username and password are implied here,
// they will most likely be form variables
$user->login( $username, $password );

// Then login the user to the forum
$phpBB = new PHPBB_Login();

$phpbb->login( $user->id );




/*  Logging out */

session_id();

$user = new User();

/* First, logout the user from the forum */
$phpBB = new PHPBB_Login();

$phpbb->logout( session_id(), $user->id) ;

/* Then logout the user from your own login system */
$user->logout( $user->id );

?>

Ejemplo 2

Código:
<?php

require_once 'class_database.php';

class login extends database
{
	/**
	 * @shortdesc : name of the phpBB user table
	 * @private
	 * @type string
	 **/
	var $userTable;
	/**
	 * @shortdesc : name of the phpBB user table
	 * @private
	 * @type string
	 **/
	var $aErrors;
	/**
	 * @shortdesc : database object
	 * @private
	 * @type mixed
	 **/
	var $oDB;
	/**
	 * @shortdesc : builder
	 * builder
	 * @param string configFile : relative url to phpBB config File
	 * @param string constantFile : relative url to phpBB constant File
	 * @public
	 * @type void
	 **/
	function login($configFile,$constantFile)
	{
		if ((!is_file($configFile))||(strpos(basename($configFile),'config.')!=0)) return $this->_err_add('invalid config file ['.$configFile.']');
        if ((!is_file($constantFile))||(strpos(basename($constantFile),'constants.')!=0)) return $this->_err_add('invalid constants file ['.$configFile.']');
		require_once($configFile);
		// set a constant to excluse the hacking attempt error
		define('IN_PHPBB',true);
		require_once($constantFile);
		$this->userTable = USERS_TABLE;
		$db = array('type' => 'mysql',
     				'login' => $dbuser,
    				'mdp'=> $dbpasswd,
     				'server' => $dbhost,
     				'db'=> $dbname
			);
		$this->oDB = new database($db);
		if (count($this->oDB->aErr)>0)
		{
			$this->aErrors = $this->oDB->aErr;
			return false;
		}
	}

	/**
	 * @shortdesc : check if a user is valid
	 * check if a user is valid
	 * @param string login : login value
	 * @param string password : password
	 * @public
	 * @type mixed
	 **/
	function verify($login,$password)
	{
		$login = addslashes($login);
		$sql = 'SELECT user_id, username, user_password, user_active, user_level FROM ' .$this->userTable. ' WHERE username = \'' . $login . "'";
		$this->oDB->execute($sql);
		if ($this->oDB->aErr) return $this->_err_add('unable to get datas from user table');
		$bResult = false;
		if( $row = $this->oDB->oR->fetchRow(DB_FETCHMODE_ASSOC))
		{
			if( md5($password) == $row['user_password'] && $row['user_active']) $bResult = intval($row['user_id']);
		}
	    return $bResult;
	}


	function _err_add($err)
	{
		$this->aErrors[] = $err;
		return false;
	}
}
?>
Para la session

Código:
<?php
require_once 'class_login.php';
$login = 'your_login_to_check';
$pass = 'your_pass_for_your_login';

$login = new login('./forum/config.php','./forum/includes/constants.php');
if (count($login->aErrors)>0) print_r($login->aErrors);
else{
 echo 'id for user ['.$login->verify($login,$pass).']';
}
?>
En el primer ejemplo, no entiendo donde hace la conexion a la db supongo por el include a common.php, ya que en el segundo si le hice la conexion

Supongo debo enviarle las variable $username y $password, desde un form, desde otro archivo

Pero me salen errores de clases no definidas

por favor, expliquenme, que debo hacer, para tener esto funcionando en un sitio, sin mostrar la cabecera y footer del PHPBB

Gracias de antemano
  #2 (permalink)  
Antiguo 19/06/2005, 09:14
 
Fecha de Ingreso: agosto-2004
Mensajes: 51
Antigüedad: 19 años, 7 meses
Puntos: 0
Me equivoque, me podrian mover el mensaje a PHP
  #3 (permalink)  
Antiguo 19/06/2005, 11:04
Avatar de Apolo
Colaborador
 
Fecha de Ingreso: abril-2003
Ubicación: ubicado
Mensajes: 7.961
Antigüedad: 21 años
Puntos: 109
Movido al foro de PHP desde Dominios y Hosting.

Saludos.
  #4 (permalink)  
Antiguo 19/06/2005, 18:27
 
Fecha de Ingreso: agosto-2004
Mensajes: 51
Antigüedad: 19 años, 7 meses
Puntos: 0
Gracias Apolo ¿Alguien en PHP me puede ayudar?
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 15:44.