Foros del Web » Programando para Internet » PHP »

como pongo el nombre de usuario cuando se logen

Estas en el tema de como pongo el nombre de usuario cuando se logen en el foro de PHP en Foros del Web. hola amigos estoy haciendo un sistema de registro de usuarios para mi web ya puse el registro y el logueo lo que quiero que cuando ...
  #1 (permalink)  
Antiguo 19/04/2012, 17:32
 
Fecha de Ingreso: marzo-2012
Mensajes: 17
Antigüedad: 12 años
Puntos: 0
Información como pongo el nombre de usuario cuando se logen

hola amigos estoy haciendo un sistema de registro de usuarios para mi web ya puse el registro y el logueo lo que quiero que cuando un usuario se loguee salga el nombre de ese usuario en la pagina estos son mis codigo


index.php contiene el logueo y una funcion que llama el registro.php


base de dato





-- Base de datos: `account`


CREATE TABLE IF NOT EXISTS `account` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`login` varchar(30) NOT NULL DEFAULT '',
`password` varchar(45) NOT NULL DEFAULT '',
`real_name` varchar(16) NOT NULL DEFAULT '',
`email` varchar(64) NOT NULL DEFAULT '',
PRIMARY KEY (`id`),
UNIQUE KEY `login` (`login`)
) ENGINE=MyISAM DEFAULT CHARSET=big5 AUTO_INCREMENT=7591 ;





codigo de registro.php


Código PHP:
//conexion a base de dato

<?php require_once('Connections/conexion_user.php'); ?>



//validador de registro

<?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  if (
PHP_VERSION 6) {
    
$theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  
$theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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")) {
  
$insertSQL sprintf("INSERT INTO account (login, password, real_name, email) VALUES (%s, %s, %s, %s)",
                       
GetSQLValueString($_POST['login'], "text"),
                       
GetSQLValueString($_POST['password'], "text"),
                       
GetSQLValueString($_POST['real_name'], "text"),
                       
GetSQLValueString($_POST['email'], "text"));

  
mysql_select_db($database_conexion_user$conexion_user);
  
$Result1 mysql_query($insertSQL$conexion_user) or die(mysql_error());

  
$insertGoTo "registro.php";
  if (isset(
$_SERVER['QUERY_STRING'])) {
    
$insertGoTo .= (strpos($insertGoTo'?')) ? "&" "?";
    
$insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  
header(sprintf("Location: %s"$insertGoTo));
}

$maxRows_Recordset1 30;
$pageNum_Recordset1 0;
if (isset(
$_GET['pageNum_Recordset1'])) {
  
$pageNum_Recordset1 $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 $pageNum_Recordset1 $maxRows_Recordset1;

mysql_select_db($database_conexion_user$conexion_user);
$query_Recordset1 "SELECT * FROM account";
$query_limit_Recordset1 sprintf("%s LIMIT %d, %d"$query_Recordset1$startRow_Recordset1$maxRows_Recordset1);
$Recordset1 mysql_query($query_limit_Recordset1$conexion_user) or die(mysql_error());
$row_Recordset1 mysql_fetch_assoc($Recordset1);

if (isset(
$_GET['totalRows_Recordset1'])) {
  
$totalRows_Recordset1 $_GET['totalRows_Recordset1'];
} else {
  
$all_Recordset1 mysql_query($query_Recordset1);
  
$totalRows_Recordset1 mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
?>
<!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=utf-8" />
<title>Documento sin título</title>
<style type="text/css">
.red {
    color: #F00;
}
</style>
</head>

<body>    <br />    
<br />
<br />
<br />    

//formulario de registro

<div class=&lt;h2>
<h3 align="center" class="red"><strong>Registrate Gratis </strong></h3>
                    </h2>
                
                </div>
  <p align="center"class="red">Todos los campos son obligatorios y deben ser completados.</p>
<form action="<?php echo $editFormAction?>" method="post" name="form1" id="form1">
  <table align="center">
    <tr valign="baseline">
      <td width="70" align="right" nowrap="nowrap">Cuenta:</td>
      <td width="228"><input name="login" type="text" value="" size="16" maxlength="16" />
      3-16 Caracteres </td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Password:</td>
      <td><input name="password" type="password" value="" size="16" maxlength="16" />
      3-16 Caracteres </td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Nombre:</td>
      <td><input name="real_name" type="text" value="" size="20" maxlength="20" />
      3-20 Caracteres </td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Email:</td>
      <td><input name="email" type="text" value="" size="20" maxlength="40" />
      Max 40 Caracteres </td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">&nbsp;</td>
      <td><input type="submit" value="Registrar" />
        <label>
          <input type="reset" name="button" id="button" value="Limpiar" />
      </label></td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="form1" />
</form>
</div>

  </div> 
                
                
                  
    </div></div>

</body>
</html>
<?php
mysql_free_result
($Recordset1);
?>
  #2 (permalink)  
Antiguo 19/04/2012, 17:35
 
Fecha de Ingreso: marzo-2012
Mensajes: 17
Antigüedad: 12 años
Puntos: 0
Información Respuesta: como pongo el nombre de usuario cuando se logen

index.php contiene el logueo y una funcion que llama el registro.php


Código PHP:
// conexion a base de dato
<?php require_once('Connections/conexion_user.php'); ?>
<?php



if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  if (
PHP_VERSION 6) {
    
$theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  
$theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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;
}
}
?>
<?php


// *** Validate request to login to this site.
if (!isset($_SESSION)) {
  
session_start();
}

$loginFormAction $_SERVER['PHP_SELF'];
if (isset(
$_GET['accesscheck'])) {
  
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset(
$_POST['cuenta'])) {
  
$loginUsername=$_POST['cuenta'];
  
$password=$_POST['password'];
  
$MM_fldUserAuthorization "";
  
$MM_redirectLoginSuccess "index1.php";
  
$MM_redirectLoginFailed "INDEX.php";
  
$MM_redirecttoReferrer false;
  
mysql_select_db($database_conexion_user$conexion_user);
  
  
$LoginRS__query=sprintf("SELECT login, password FROM account WHERE login=%s AND password=%s",
    
GetSQLValueString($loginUsername"text"), GetSQLValueString($password"text")); 
   
  
$LoginRS mysql_query($LoginRS__query$conexion_user) or die(mysql_error());
  
$loginFoundUser mysql_num_rows($LoginRS);
  if (
$loginFoundUser) {
     
$loginStrGroup "";
    
    if (
PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
    
//declare two session variables and assign them
    
$_SESSION['MM_Username'] = $loginUsername;
    
$_SESSION['MM_UserGroup'] = $loginStrGroup;          

    if (isset(
$_SESSION['PrevUrl']) && false) {
      
$MM_redirectLoginSuccess $_SESSION['PrevUrl'];    
    }
    
header("Location: " $MM_redirectLoginSuccess );
  }
  else {
    
header("Location: "$MM_redirectLoginFailed );
  }
}
?>


//formulario de logeo

<div id="apDiv1">
  <form id="form1" name="form1" method="POST" action="<?php echo $loginFormAction?>">
    <div align="right">
      <table width="371" border="0">
        <tr>
          <td width="155" height="28"><span id="sprytextfield1">
            <label>
              <input name="cuenta" type="text" id="cuenta" value="Cuenta" />
            </label>
          <span class="textfieldRequiredMsg">Se necesita un valor.</span></span></td>
          <td width="151"><span id="sprytextfield2">
            <label>
              <input name="password" type="password" id="password" value="Password" />
            </label>
          <span class="textfieldRequiredMsg">Se necesita un valor.</span></span></td>
          <td width="30"><input type="submit" name="button" id="button" value="Entrar" /></td>
          <td width="17"><input type="reset" name="button2" id="button2" value="Limpiar" /></td>
        </tr>
        <tr>
          <td height="27" colspan="4">Has Olvidado la Clave</td>
        </tr>
      </table>
    </div>
  </form>
</div>
<div class="sidebar1">
  
  
  <div id="content">            <div id="content">

<div class="con-wrap">
<div id="fuibar"><!--xxxxxxxxxx-->

            

<h3 align="right">
<?= date("d/m/Y"); ?></span></h3>
<h3 align="right"><span>
  <?php 
date_default_timezone_set
("America/Caracas" ) ; 
$hora date('h:i a',time() - 3600*date('I')); 
print 
"&nbsp;$hora&nbsp;"
?>  
</h3>
</div>
<br />            
</center>
<center>
<object width="370" height="290"><param name="movie" value="http://www.youtube.com/v/F3Id9qf3YC0"></param><embed src="http://www.youtube.com/v/F3Id9qf3YC0" type="application/x-shockwave-flash" width="370" height="290"></embed></object>
</center>

</div></div>



  </div>

</div> 
                
                  
</div></div>

</div>

  </div> 
                
                
                  
    </div></div>
    
    <!-- end .sidebar1 -->
    
 //esto llama al registro.php

    <?PHP
            $includeDir 
".".DIRECTORY_SEPARATOR;
            
DIRECTORY_SEPARATOR
            
$includeDefault $includeDir."registro.php";
            
            if(isset(
$_GET['s']) && !empty($_GET['s']))
            {
            
                
$_GET['s'] = str_replace("\0"''$_GET['s']);
                
$includeFile basename(realpath($includeDir.$_GET['s'].".php"));
                
$includePath $includeDir.$includeFile;
                
                if(!empty(
$includeFile) && file_exists($includePath)) 
                {
                    include(
$includePath);
                }
                else 
                {
                include(
$includeDefault);
                }

            } 
            else 
            {
                include(
$includeDefault);
            }
        
?>

  <!-- end .content --></div>
  <!-- end .container -->
</div>
<script type="text/javascript">
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1");
var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2");
</script>
</body>
</html>
  #3 (permalink)  
Antiguo 19/04/2012, 17:38
Avatar de gjx2  
Fecha de Ingreso: agosto-2008
Ubicación: R.D
Mensajes: 1.153
Antigüedad: 15 años, 8 meses
Puntos: 139
Respuesta: como pongo el nombre de usuario cuando se logen

Imprime esta $_SESSION['MM_Username'] variable de session donde desees que salga el nombre de usuario.


Saludos.
  #4 (permalink)  
Antiguo 20/04/2012, 11:29
 
Fecha de Ingreso: marzo-2012
Mensajes: 17
Antigüedad: 12 años
Puntos: 0
Respuesta: como pongo el nombre de usuario cuando se logen

gracias amigo me funciono muy bien

Etiquetas: formulario, html, mysql, nombre, pongo, registro, sql, usuarios
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:12.