Foros del Web » Programando para Internet » PHP »

problema

Estas en el tema de problema en el foro de PHP en Foros del Web. Hola mi nombre es fernando soy de montevideo y estoy en busca de ayuda... mi problema es el siguiente : estoy realizando un web pero ...
  #1 (permalink)  
Antiguo 24/04/2011, 16:26
Usuario no validado
 
Fecha de Ingreso: febrero-2008
Ubicación: Montevideo
Mensajes: 142
Antigüedad: 16 años, 2 meses
Puntos: 7
problema

Hola mi nombre es fernando soy de montevideo y estoy en busca de ayuda...

mi problema es el siguiente : estoy realizando un web pero estoy trancado, miren lo que me pasa es que no me doy cuenta como hacer para que cuando una persona se identifica valla a a su cuenta y que la sesion a su ves quede identificada en el resto de las paginas y que cuando cierre sesión esta se destruya tambien en todas las paginas

estas son las paginas de identificación y micuenta :


-------------------------------------------------------------------------------------------------------
ingresar.php

Código PHP:
<?php require_once('Connections/ofertas.php'); ?>
<?php

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

if (isset(
$_POST['Email'])) {
  
$loginUsername=$_POST['Email'];
  
$password=$_POST['Email'];
  
$MM_fldUserAuthorization "";
  
$MM_redirectLoginSuccess "micuenta.php";
  
$MM_redirectLoginFailed "no_usuario.php";
  
$MM_redirecttoReferrer false;
  
mysql_select_db($database_ofertas$ofertas);
  
  
$LoginRS__query=sprintf("SELECT Email, Email FROM registrarse WHERE Email='%s' AND Email='%s'",
    
get_magic_quotes_gpc() ? $loginUsername addslashes($loginUsername), get_magic_quotes_gpc() ? $password addslashes($password)); 
   
  
$LoginRS mysql_query($LoginRS__query$ofertas) or die(mysql_error());
  
$loginFoundUser mysql_num_rows($LoginRS);
  if (
$loginFoundUser) {
     
$loginStrGroup "";
    
    
// Declara dos variables de sesión y asignarlos 
    
$_SESSION['MM_Username'] = $loginUsername;
    
$_SESSION['MM_UserGroup'] = $loginStrGroup;          

    if (isset(
$_SESSION['micuenta.php']) && true) {
      
$MM_redirectLoginSuccess $_SESSION['micuenta.php'];    
    }
    
header("Location: " $MM_redirectLoginSuccess );
  }
  else {
    
header("Location: "$MM_redirectLoginFailed );
  }
}
?>
<!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></title>

<style type="text/css">
<!--
#ingresar {
    position:absolute;
    left:500px;
    top:250px;
    width:350px;
    height:25px;
    z-index:1;
    font-family: "Times New Roman", Times, serif;
    font-size: 14px;
    font-style: normal;
    color: #0066FF;
    -moz-border-radius:13px;
-webkit-border-radius:13px;
border-radius:13px;
/*IE DOES NOT SUPPORT BORDER RADIUS*/
-moz-box-shadow:inset 0px 0px 20px #000000;
-webkit-box-shadow:inset 0px 0px 20px #000000;
box-shadow:inset 0px 0px 20px #000000;
/*Inner elements should not cover inner shadows*/
/*Chrome renders inset shadows incorrectly with border-radius*/
/*IE DOES NOT SUPPORT INSET SHADOWS*/

}
.Estilo1 {
    font-size: 12px;
    color: #FFFFFF;
}
-->
</style>
<script type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}
//-->
</script>
</head>

<body>
<div id="ingresar">
  <form method="POST" name="form1" action="<?php echo $loginFormAction?>">
    <table width="300" align="center">
      <tr valign="baseline">
        <td><p align="center">
          Email:
            <input name="Email" type="text" onblur="MM_validateForm('Email','','RisEmail');return document.MM_returnValue" value="" size="20">
          <input name="submit" type="submit" value="Ir " />
        </p>        </td>
      </tr>
    </table>
    <input type="hidden" name="id_registrar" value="">
  </form>
</div>

</body>
</html>
<?php include("logo.php"); ?>
<?php 
include("otromenu.php"); ?>
<?php 
include("menu.php"); ?>
----------------------------------------------------------------------------------------------------
micuenta.php

Código PHP:
<?php require_once('Connections/ofertas.php'); ?>
<?php
// inicializar la sesión
  
session_start();
    if (isset(
$_SESSION['micuenta.php']) && true) {
}

// ** Cerrar sesión del usuario actual. **
$logoutAction $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset(
$_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
  
$logoutAction .="&"htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset(
$_GET['doLogout'])) &&($_GET['doLogout']=="true")){
// Iniciar sesión totalmente a un visitante que tenemos que borrar la sesión varialbles 
  
$_SESSION['MM_Username'] = NULL;
  
$_SESSION['MM_UserGroup'] = NULL;
  
$_SESSION['PrevUrl'] = NULL;
  unset(
$_SESSION['MM_Username']);
  unset(
$_SESSION['MM_UserGroup']);
  unset(
$_SESSION['PrevUrl']);
    
  
$logoutGoTo "index.php";
  if (
$logoutGoTo) {
    
header("Location: $logoutGoTo");
    exit;
  }
}
?>
<?php
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_update"])) && ($_POST["MM_update"] == "form1")) {
  
$updateSQL sprintf("UPDATE registrarse SET Email=%s WHERE Nombre=%s",
                       
GetSQLValueString($_POST['Email'], "text"),
                       
GetSQLValueString($_POST['Nombre'], "text"));

  
mysql_select_db($database_ofertas$ofertas);
  
$Result1 mysql_query($updateSQL$ofertas) or die(mysql_error());

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

mysql_select_db($database_ofertas$ofertas);
$query_datos "SELECT Email, Nombre FROM registrarse";
$datos mysql_query($query_datos$ofertas) or die(mysql_error());
$row_datos mysql_fetch_assoc($datos);
$totalRows_datos mysql_num_rows($datos);
?><!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>Bienvenido <?php echo $row_micuenta['Nombre']; ?></title>
<style type="text/css">
<!--
#micuenta {
    position:absolute;
    left:950px;
    top:100px;
    width:350px;
    height:100px;
    z-index:1;
    font-family: "Times New Roman", Times, serif;
    font-size: 14px;
    color: #ffffFF;
}
#Layer1 {
    position:absolute;
    left:46px;
    top:89px;
    width:93px;
    height:69px;
    z-index:1;
}
-->
</style>
</head>

<body>
<div id="micuenta">
  <p><a href="<?php echo $logoutAction ?>">Desconectar</a></p>
  <p>E-mail : <?php echo $row_datos['Email']; ?></p>
  <p>Nombre : <?php echo $row_datos['Nombre']; ?></p>
  <p>&nbsp;</p>

  <form method="post" name="form1" action="<?php echo $editFormAction?>">
    <table align="center">
      <tr valign="baseline">
        <td nowrap align="right">Email:</td>
        <td><input type="text" name="Email" value="<?php echo $row_datos['Email']; ?>" size="32"></td>
      </tr>
      <tr valign="baseline">
        <td nowrap align="right">Nombre:</td>
        <td><input type="text" name="Nombre" value="<?php echo $row_datos['Nombre']; ?>" size="32"></td>
      </tr>
      <tr valign="baseline">
        <td nowrap align="right">&nbsp;</td>
        <td><input type="submit" value="Actualizar registro"></td>
      </tr>
    </table>
    <input type="hidden" name="MM_update" value="form1">
    <input type="hidden" name="Nombre" value="<?php echo $row_datos['Nombre']; ?>">
  </form>
  <p>&nbsp;</p>
</div>
</body>
</html>
<?php
mysql_free_result
($datos);
?>
<?php 
include("logo.php"); ?>
<?php 
include("otromenu.php"); ?>
<?php 
include("menus.php"); ?>
por favor si alguien me puede ayudar estaria muy agradecido
  #2 (permalink)  
Antiguo 24/04/2011, 17:32
Avatar de bocho0610  
Fecha de Ingreso: enero-2010
Ubicación: <? echo "Santiago, Chile"; ?>
Mensajes: 341
Antigüedad: 14 años, 3 meses
Puntos: 26
Respuesta: problema

me carga analizar codigos extensos, pero te puedo orientar.

Con poner $session_start(); al comienzo de cada pagina, haces que las variables de session ($_SESSION['algo'];) se expandan por todo el sitio, cuando identificas un usuario tomando desde la base de datos:

identificar.php
Código PHP:
Ver original
  1. $_SESSION['nombre'] = $row['nombre'];
  2. $_SESSION['email'] = $row['email'];
  3. $_SESSION['edad'] = $row['edad'];

perfil.php
Código PHP:
Ver original
  1. echo "Su nombre es ".$_SESSION['nombre']." y su email es ".$_SESSION['email'];

Para destruir sesiones se usa $session_destroy() y con esto haces que se eliminen todas las sessiones creadas con anterioridad.

Espero haberte orientado en algo.
__________________
Sigueme en Twitter!
Septimoarte.cl <-- Un mundo en cine.
  #3 (permalink)  
Antiguo 24/04/2011, 18:26
 
Fecha de Ingreso: mayo-2006
Mensajes: 288
Antigüedad: 17 años, 10 meses
Puntos: 4
Respuesta: problema

ja ja no es asi seria algo más facil yo trabajo asi:

3 archivos:

index.php
login.php
private.php


En index.php hago
Código PHP:
<?
session_start
();
var 
auth $_SESSION['auth'];
if(
$auth == ""){
include 
"login.php";
}else if(
$auth == "XLogedX"){
include 
"private.php";
}
?>
En login.php pongo:

Código PHP:
<?
session_start
();
//aqui todo lo concerniente a login..
//Si el login funciono correcctamente hago :$_SESSION['auth']='XLogedX';
//De lo contrario Simplemente vuelvo a mostrar el formulario.
?>
Y asi private será accedido no sin antes pasar por login.php.

Aora para qe no se salteen el paso has esto:
Las conexiones a base de datos incluyelas en index.php, ASI los que entren directamente a private.php no podran ver nada pss les falta la conexion a mysql usada en index.php, variables y conexiones que serán heredadas por la inclusion.

Etiquetas: Ninguno
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

SíEste tema le ha gustado a 1 personas




La zona horaria es GMT -6. Ahora son las 20:25.