
variables de sesion
Publicado por Fran (9 intervenciones) el 27/06/2011 20:33:17
Hola a todos, mi problema es el siguiente...he creado una aplicacion web para gestionar los clientes, vehiculos, trabajos realizados etc... de un taller mecanico. Hasta aqui bien... pero lo que estoy intentado es que los clientes, despues de haberles asignado un usuario y una contraseña, puedan desde su casas acceder al sitio y ver la informacion relativa a sus vehiculos... es decir, si accedo con mi usuario vere primero la matricula de mi coche y al pinchar sobre ella...los trabajos que se le hayan hecho y la proxima revision.
El caso es que he conseguido que cada usuario, al acceder al sitio vean un mensaje de bienvenida con el nombre de su usuario..epro no soy capaz de que se muestren las matriculas de sus coches...
Paso a detalalr como esta montado:
- desde el Index..el usuario introduce su usuario y contraseña: el codigo de index.php es el siguiente:
<?php require_once('../Connections/conexion.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$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['login'])) {
$loginUsername=$_POST['login'];
$password=$_POST['password'];
$MM_fldUserAuthorization = "";
$MM_redirectLoginSuccess = "zonaprivada.php";
$MM_redirectLoginFailed = "incorrecto.php";
$MM_redirecttoReferrer = false;
mysql_select_db($database_conexion, $conexion);
$LoginRS__query=sprintf("SELECT Usuario, Password FROM usuarios WHERE Usuario=%s AND Password=%s",
GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
$LoginRS = mysql_query($LoginRS__query, $conexion) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup = "";
//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 );
}
}
?>
<?php $_SESSION['login']=$loginUsername; ?>
cuando el login es correcto es dirigido a zonapriovada.php cuyo codigo es el siguiente:
<?php require_once('../Connections/conexion.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$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;
}
}
$colname_matriclientes = "-1";
if (isset($_SESSION['login'])) {
$colname_matriclientes = $_SESSION['login'];
}
mysql_select_db($database_conexion, $conexion);
$query_matriclientes = sprintf("SELECT Matricula FROM usuarios WHERE Usuario = %s", GetSQLValueString($colname_matriclientes, "text"));
$matriclientes = mysql_query($query_matriclientes, $conexion) or die(mysql_error());
$row_matriclientes = mysql_fetch_assoc($matriclientes);
$totalRows_matriclientes = mysql_num_rows($matriclientes);
session_start();?>
Pues bien.. en esta ultima pagina (zonaprivada.php) tengo un juego de registros que me devuelve la matricula segun el usuario. A este juego de registros le he llamado "matriclientes". Pues bien, si visualizo una prueba del juego de registros me devuelve la matricula..pero a la hora de que funcione realmente ...no me muestra nada....
Para que me lo muestre tengo un DIV que contiene:
<div id="labell">Bienvenido <?php echo $_SESSION['login'] ?><br />
<?php echo $row_matriclientes['Matricula']; ?>
</div>
Como he dicho antes, el usuario si me lo muestra pero no su matricula correspondiente.
Podria ayudarme alguien y decirme donde estoy fallando.
Muchas gracias de antemano.
El caso es que he conseguido que cada usuario, al acceder al sitio vean un mensaje de bienvenida con el nombre de su usuario..epro no soy capaz de que se muestren las matriculas de sus coches...
Paso a detalalr como esta montado:
- desde el Index..el usuario introduce su usuario y contraseña: el codigo de index.php es el siguiente:
<?php require_once('../Connections/conexion.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$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['login'])) {
$loginUsername=$_POST['login'];
$password=$_POST['password'];
$MM_fldUserAuthorization = "";
$MM_redirectLoginSuccess = "zonaprivada.php";
$MM_redirectLoginFailed = "incorrecto.php";
$MM_redirecttoReferrer = false;
mysql_select_db($database_conexion, $conexion);
$LoginRS__query=sprintf("SELECT Usuario, Password FROM usuarios WHERE Usuario=%s AND Password=%s",
GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
$LoginRS = mysql_query($LoginRS__query, $conexion) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup = "";
//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 );
}
}
?>
<?php $_SESSION['login']=$loginUsername; ?>
cuando el login es correcto es dirigido a zonapriovada.php cuyo codigo es el siguiente:
<?php require_once('../Connections/conexion.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$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;
}
}
$colname_matriclientes = "-1";
if (isset($_SESSION['login'])) {
$colname_matriclientes = $_SESSION['login'];
}
mysql_select_db($database_conexion, $conexion);
$query_matriclientes = sprintf("SELECT Matricula FROM usuarios WHERE Usuario = %s", GetSQLValueString($colname_matriclientes, "text"));
$matriclientes = mysql_query($query_matriclientes, $conexion) or die(mysql_error());
$row_matriclientes = mysql_fetch_assoc($matriclientes);
$totalRows_matriclientes = mysql_num_rows($matriclientes);
session_start();?>
Pues bien.. en esta ultima pagina (zonaprivada.php) tengo un juego de registros que me devuelve la matricula segun el usuario. A este juego de registros le he llamado "matriclientes". Pues bien, si visualizo una prueba del juego de registros me devuelve la matricula..pero a la hora de que funcione realmente ...no me muestra nada....
Para que me lo muestre tengo un DIV que contiene:
<div id="labell">Bienvenido <?php echo $_SESSION['login'] ?><br />
<?php echo $row_matriclientes['Matricula']; ?>
</div>
Como he dicho antes, el usuario si me lo muestra pero no su matricula correspondiente.
Podria ayudarme alguien y decirme donde estoy fallando.
Muchas gracias de antemano.
Valora esta pregunta


0