Foros del Web » Programando para Internet » PHP »

Añadir usuario

Estas en el tema de Añadir usuario en el foro de PHP en Foros del Web. Hola a todos, Estoy haciendo una aplicacion para una base de datos. Lo que quiero es que el administrador pueda añadir a un nuevo usuario ...
  #1 (permalink)  
Antiguo 17/10/2007, 10:30
 
Fecha de Ingreso: agosto-2007
Mensajes: 64
Antigüedad: 16 años, 8 meses
Puntos: 0
Añadir usuario

Hola a todos,

Estoy haciendo una aplicacion para una base de datos. Lo que quiero es que el administrador pueda añadir a un nuevo usuario (e.j. un nuevo trabajador que vaya a la empresa y tenga que acceder a una seccion determinada). La base de datos esta dividida en 4 secciones en los que lostrabajadores solo pueden acceder a su seccion. Me gustaria que el administrador pudiese darle de alta y darle el permiso para poder acceder a la seccion a la que vaya, pero sin acceder al codigo. Por ejemplo que le salga una pantalla en la que ponga el nombre_usuario y a la seccion a la que podra acceder.

como podria hacerlo?

Gracias y saludos
  #2 (permalink)  
Antiguo 17/10/2007, 22:56
 
Fecha de Ingreso: mayo-2006
Ubicación: Bogotá
Mensajes: 2.061
Antigüedad: 18 años
Puntos: 50
Re: Añadir usuario

pes lo que puede es asignar perfiles a cada usuario.

ejemplo
Si el usuario supervisor solo puede entrar al area A, al crear el usuario del supervisor cree un campo que se llame perfil y en cada un ode los archivos de }l area A verifica si usuario actual tiene ese perfil puiede ver contenido sino pues no.

eso es un lio si no sabe manejar sesuiones y todo ese cuento "por experiencia propia " dreamweaver crea un sistema de usuarios con perfiles pruebve son ese o busque por hay hay varios prefabricados de ese estilo

Me avisa si pudo y si consigue uno bueno me lo pasa por fa

Suerte
  #3 (permalink)  
Antiguo 17/10/2007, 23:39
 
Fecha de Ingreso: agosto-2007
Mensajes: 64
Antigüedad: 16 años, 8 meses
Puntos: 0
Re: Añadir usuario

Hola,

Gracias por la respuesta. Lo intentare a ver que sale. Si hago uno decente ya te lo pasare.

Gracias y saludos
  #4 (permalink)  
Antiguo 18/10/2007, 03:02
 
Fecha de Ingreso: agosto-2007
Mensajes: 64
Antigüedad: 16 años, 8 meses
Puntos: 0
Re: Añadir usuario

Hola a todos,

Ya he solucionado este problemilla. Aqui os dejo la forma en que he hecho añadir un usario y Darle acceso a una seccion especifica:

ESTE ES EL FORMULARIO DONDE VEO LOS USUARIOS, CONTRASEÑAS Y LAS SECCIONES QUE HAY Y DONDE INSERTO UN NUEVO USUARIO, CONTRASEÑA Y USUARIO

Código PHP:
<?php require_once('Connections/Datuak3.php'); ?>
<?php
// AQUI SE COMPRUEBA SI EXISTE EL USUARIO

$MM_flag="MM_insert";
if (isset(
$_POST[$MM_flag])) {
  
$MM_dupKeyRedirect="ErabilGehi.php?Errorea=bai";
  
$loginUsername $_POST['Usuario'];
  
$LoginRS__query "SELECT Usuario FROM tabla WHERE Usuario='" $loginUsername "'";
  
mysql_select_db($database_Datuak3$Datuak3);
  
$LoginRS=mysql_query($LoginRS__query$Datuak3) or die(mysql_error());
  
$loginFoundUser mysql_num_rows($LoginRS);

requested username
  
if($loginFoundUser){
    
$MM_qsChar "?";
    if (
substr_count($MM_dupKeyRedirect,"?") >=1$MM_qsChar "&";
    
$MM_dupKeyRedirect $MM_dupKeyRedirect $MM_qsChar ."requsername=".$loginUsername;
    
header ("Location: $MM_dupKeyRedirect");
    exit;
  }
}

function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch (
$theType) {
    case 
"text":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;    
    case 
"long":
    case 
"int":
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case 
"double":
      
$theValue = ($theValue != "") ? "'" doubleval($theValue) . "'" "NULL";
      break;
    case 
"date":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;
    case 
"defined":
      
$theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
      break;
  }
  return 
$theValue;
}

$editFormAction $_SERVER['PHP_SELF'];
if (isset(
$_SERVER['QUERY_STRING'])) {
  
$editFormAction .= "?" htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset(
$_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {

//LE OBLIGO A METER LAS SECCIONES ESPECIFICAS Y SI QUIERE UN UEVO ADMINISTRADOR

 
if (($_POST["Seccion"] == "LaSeccion1") || ($_POST["Seccion"] == "LaSeccion2") || ($_POST["Seccion"] == "LaSeccion3") || ($_POST["Seccion"] == "LaSeccion4") || ($_POST["Seccion"] == "Admnistrador") || (!empty($_POST["Seccion"]))){
  
$insertSQL sprintf("INSERT INTO tabla (Id, Usuario, Contraseña, Seccion) VALUES (%s, %s, %s, %s)",

                       
GetSQLValueString($_POST['Id'], "int"),
                       
GetSQLValueString(ucfirst($_POST['Usuario']), "text"),
                       
GetSQLValueString(ucfirst($_POST['Contraseña']), "text"),
                       
GetSQLValueString(ucfirst($_POST['Seccion']), "text"));

  
mysql_select_db($database_Datuak3$Datuak3);
  
$Result1 mysql_query($insertSQL$Datuak3) or die(mysql_error());
 
 }else{
  
  echo 
"LAS SeccionES SOLO PUEDEN SER LaSeccion1, LaSeccion2, LaSeccion3, LaSeccion4 O ADMINISTRADOR Y NO PUEDE ESTAR VACIO";
 
 }
}

//AQUI HAGO EL SELECT PARA VER LOS USUARIOS, CONTRASEÑAS Y SECCIONES QUE HAY

mysql_select_db($database_Datuak3$Datuak3);
$query_ErabilPasa "select * from tabla";
$ErabilPasa mysql_query($query_ErabilPasa$Datuak3) or die(mysql_error());
$row_ErabilPasa mysql_fetch_assoc($ErabilPasa);
$totalRows_ErabilPasa mysql_num_rows($ErabilPasa);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Usuario eta Contraseña gehitu</title>
<style type="text/css">
<!--
.Estilo1 {
    font-size: 24px;
    font-weight: bold;
}
-->
</style>
</head>

<body>
<p align="center" class="Estilo1"><u>Usuario eta Contraseña gehitu </u></p>
<p>&nbsp;</p>

<p>
<?
 
if ($_GET["Errorea"]=="bai"){
   echo 
"Usuario existitzen da";
 }
?>
</p>
<p>&nbsp;</p>

<table border="1">
  <tr align="center">
    <td width="155"><u><strong>Usuario</strong></u></td>
    <td width="155"><u><strong>Contraseña</strong></u></td>
    <td width="174"><u><strong>Seccion</strong></u></td>
  </tr>
  <?php do { ?>
    <tr>
      <td><?php echo $row_ErabilPasa['Usuario']; ?></td>
      <td><?php echo $row_ErabilPasa['Contraseña']; ?></td>
      <td><?php echo $row_ErabilPasa['Seccion']; ?></td>
    </tr>
    <?php } while ($row_ErabilPasa mysql_fetch_assoc($ErabilPasa)); ?>
</table>
<p>&nbsp;</p>
<form method="post" name="form1" action="<?php echo $editFormAction?>">
  <table border="1" align="center">
    <tr valign="baseline">
      <td width="157" align="left" nowrap>Usuario</td>
      <td width="192"><input type="text" name="Usuario" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="left">Contraseña</td>
      <td><input type="text" name="Contraseña" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="left">Seccion</td>
      <td><input type="text" name="Seccion" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="left">&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  </table>
  <p>
    <input type="hidden" name="IdErabilPasa" value="">
    <input type="hidden" name="MM_insert" value="form1">
 </p>
  <p>   
    <input name="submit" type="submit" value="Insertar registro" />
  </p>
</form>
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result
($ErabilPasa);
?>
ESTE ES FORMULARIO DONDE INTRODUZCO EL USUARIO Y LA CONTRASEÑA:

Código PHP:
<body>  
<form action="Control.php" method="POST"> 
<table align="center" width="225" cellspacing="2" cellpadding="2" border="0"> 
<tr> 
<td colspan="2" align="center" 
<? if ($_GET["errorusuario"]=="si"){?> 
bgcolor=white><span class="Estilo2" style="color:ffffff"><b>Usuario edo Contraseña ez dira zuzenak</b></span> 
<?}else{?> 
bgcolor=white><span class="Estilo2"> Introduzca Usuario Y Contraseña</span><?}?></td> 
</tr> 
<tr> 
<td align="left"><span class="Estilo1">Usuario</span></td> 
<td><input name="Usuario" type="Text" id="Usuario" size="20" maxlength="50"></td> 
</tr> 
<tr> 
<td align="left"><span class="Estilo1">Contraseña</span></td> 
<td><input name="Contraseña" type="password" id="Contraseña" size="20" maxlength="50" /></td>
</tr> 
<tr> 
<td colspan="2" align="center"><input type="Submit" class="big" value="Sartu"></td> 
</tr> 
</table>  
</form> 
</body> 
</html>
Aqui es donde hago la comprobacion de si existe el usuario, contraseña y seccion:

Código PHP:
<body>

<? 
//conecto con la base de datos 
$conn mysql_connect("localhost","usuario","contarseña"); 
//selecciono la BBDD 
mysql_select_db("Datuak3",$conn); 

//Sentencia SQL para buscar un usuario con esos datos 
$ssql "SELECT * FROM tabla WHERE Usuario='".ucfirst($_POST['Usuario'])."' and Contraseña='".ucfirst($_POST['Contraseña'])."' and Seccion='Laseccion1' "

//Ejecuto la sentencia 
$rs mysql_query($ssql,$conn); 

$ssql2 "SELECT * FROM ErabilPasa WHERE Usuario='".ucfirst($_POST['Usuario'])."' and Contraseña='".ucfirst($_POST['Contraseña'])."' and Seccion='Laseccion2' "

$rs2 mysql_query($ssql2,$conn);


$ssql3 "SELECT * FROM ErabilPasa WHERE Usuario='".ucfirst($_POST['Usuario'])."' and Contraseña='".ucfirst($_POST['Contraseña'])."' and Seccion='Laseccion3' "

$rs3 mysql_query($ssql3,$conn); 


$ssql4 "SELECT * FROM ErabilPasa WHERE Usuario='".ucfirst($_POST['Usuario'])."' and Contraseña='".ucfirst($_POST['Contraseña'])."' and Seccion='Laseccion3' "

$rs4 mysql_query($ssql4,$conn); 


$ssql5 "SELECT * FROM ErabilPasa WHERE Usuario='".ucfirst($_POST['Usuario'])."' and Contraseña='".ucfirst($_POST['Contraseña'])."' and Seccion='Administrador' "

$rs5 mysql_query($ssql5,$conn); 

//vemos si el usuario y contraseña es váildo 
//si la ejecución de la sentencia SQL nos da algún resultado 
//es que si que existe esa conbinación usuario/contraseña/Seccion

if (mysql_num_rows($rs)!=0){ 
    
//usuario y contraseña válidos 
    //defino una sesion y guardo datos 
    
session_start(); 
    
session_register("autentificado"); 
    
$autentificado "SI";
    
header ("Location: Laseccion1.php");     
}elseif (
mysql_num_rows($rs2)!=0){ 
    
session_start(); 
    
session_register("autentificado"); 
    
$autentificado "SI";
    
header ("Location: Laseccion2.php"); 
}elseif (
mysql_num_rows($rs3)!=0){  
    
session_start(); 
    
session_register("autentificado"); 
    
$autentificado "SI";
    
header ("Location: Laseccion3.php"); 
}elseif (
mysql_num_rows($rs4)!=0){  
    
session_start(); 
    
session_register("autentificado"); 
    
$autentificado "SI";
    
header ("Location: Laseccion4.php"); 
}elseif (
mysql_num_rows($rs5)!=0){  
    
session_start(); 
    
session_register("autentificado"); 
    
$autentificado "SI";
    
header ("Location: Administrador.php"); 
}else { 
    
//si no existe le mando otra vez a la portada 
    
header("Location: index.php?errorusuario=si"); 


mysql_free_result($rs); 
mysql_free_result($rs2);
mysql_free_result($rs3);
mysql_free_result($rs4);
mysql_close($conn); 
?> 

</body>
</html>
Seguro que se puede mejorar muchisimo pero a mi asi me funciona. Espero que os sirva de algo aunque sea para echros unas risas.

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:36.