Foros del Web » Programando para Internet » PHP »

manejar script de login php

Estas en el tema de manejar script de login php en el foro de PHP en Foros del Web. Hola mi nombre es fernando, estoy desarrollando un sitio web, pero me encuentro trancado con este temita del login de usuario. el login en si ...
  #1 (permalink)  
Antiguo 18/04/2011, 07:50
Usuario no validado
 
Fecha de Ingreso: febrero-2008
Ubicación: Montevideo
Mensajes: 142
Antigüedad: 16 años, 2 meses
Puntos: 7
De acuerdo manejar script de login php

Hola mi nombre es fernando, estoy desarrollando un sitio web, pero me encuentro trancado con este temita del login de usuario.

el login en si esta bien no tengo problemas con eso, pero lo que yo quiero es que cuando alguien se logea desaparezca el ingresar y aparezca otra información como Bienvenido fulanito, me entienden y esto en todas las paginas de mi web y que no me pida ingresar cada ves que estoy en el sitio. me entienden?

este es el escript del login :
Código PHP:
<?php require_once('Connections/ofertas.php'); ?>
<?php
// *** Redirigir nombre de usuario si existe
$MM_flag="MM_insert";
if (isset(
$_POST[$MM_flag])) {
  
$MM_dupKeyRedirect="micuenta.php";
  
$loginUsername $_POST['Email'];
  
$LoginRS__query "SELECT Email FROM registrarse WHERE Email='" $loginUsername "'";
  
mysql_select_db($database_ofertas$ofertas);
  
$LoginRS=mysql_query($LoginRS__query$ofertas) or die(mysql_error());
  
$loginFoundUser mysql_num_rows($LoginRS);

  
//si hay una fila en la base de datos, el nombre de usuario se encontró - no se puede agregar el nombre de usuario solicitado
  
if($loginFoundUser){
    
$MM_qsChar "?";
    
//añadir el nombre de usuario a la página de redireccionamiento
    
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")) {
  
$insertSQL sprintf("INSERT INTO registrarse (id_registrar, Email) VALUES (%s, %s)",
                       
GetSQLValueString($_POST['id_registrar'], "int"),
                       
GetSQLValueString($_POST['Email'], "text"));

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

  
$insertGoTo "micuenta.php";
  if (isset(
$_SERVER['QUERY_STRING'])) {
    
$insertGoTo .= (strpos($insertGoTo'?')) ? "&" "?";
    
$insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  
header(sprintf("Location: %s"$insertGoTo));
}
?><?php
// *** Validar solicitud para ingresar a este sitio.
if (!isset($_SESSION)) {
  
session_start();
}

$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['PrevUrl']) && false) {
      
$MM_redirectLoginSuccess $_SESSION['PrevUrl'];    
    }
    
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>
<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>
<style type="text/css">
<!--
#ingresar {
    position:absolute;
    left:410px;
    top:250px;
    width:350px;
    height:25px;
    z-index:1;
    font-family: "Times New Roman", Times, serif;
    font-size: 14px;
    font-style: normal;
    color: #0066FF;
}
-->
</style>
</head>

<body>
<div id="ingresar">
  <form method="POST" name="form1" action="<?php echo $loginFormAction?>">
    <table align="center">
      <tr valign="baseline">
        <td align="right" nowrap>Email:
          <input name="Email" type="text" onblur="MM_validateForm('Email','','RisEmail');return document.MM_returnValue" value="" size="10" />
          <input name="submit" type="submit" value="Ir" /></td>
      </tr>
    </table>
    <input type="hidden" name="id_registrar" value="">
    <input type="hidden" name="MM_insert" value="form1">
  </form>
</div>
</body>
</html>
<?php include("otromenu.php"); ?>
<?php 
include("menu.php"); ?>
Bueno espero me puedan ayudar
muchisimas graciasssss
  #2 (permalink)  
Antiguo 18/04/2011, 07:57
Avatar de jotaincubus  
Fecha de Ingreso: mayo-2005
Ubicación: Medellin - Colombia
Mensajes: 1.797
Antigüedad: 18 años, 11 meses
Puntos: 394
Respuesta: manejar script de login php

Lo que puede hacer es crear una condicion para verificar si la sesion existe o no, te muestro un pequeño ejemplo:

Código PHP:
Ver original
  1. <?php
  2. if (isset($_SESSION['MM_Username']) && $_SESSION['MM_Username'] != ""){
  3. // muestro el nombre de usuario
  4. }else{
  5. // muestro el formulario de inicio de sesion   
  6. }
  7. ?>
__________________
Por que existe gente que no agradece después de que se le ha brindado tiempo y ayuda ???
  #3 (permalink)  
Antiguo 18/04/2011, 08:09
Usuario no validado
 
Fecha de Ingreso: febrero-2008
Ubicación: Montevideo
Mensajes: 142
Antigüedad: 16 años, 2 meses
Puntos: 7
Respuesta: manejar script de login php

Cita:
Iniciado por jotaincubus Ver Mensaje
Lo que puede hacer es crear una condicion para verificar si la sesion existe o no, te muestro un pequeño ejemplo:

Código PHP:
Ver original
  1. <?php
  2. if (isset($_SESSION['MM_Username']) && $_SESSION['MM_Username'] != ""){
  3. // muestro el nombre de usuario
  4. }else{
  5. // muestro el formulario de inicio de sesion    
  6. }
  7. ?>

Muchas gracias por responder tan rapido amigo.. una preguntita más ¿adonde dice muestro formulario de inicio pongo un vinculo al formulario o pongo el mismo?

bueno disculpa mi ignorancia...



Graciassssss
  #4 (permalink)  
Antiguo 18/04/2011, 08:15
Avatar de jotaincubus  
Fecha de Ingreso: mayo-2005
Ubicación: Medellin - Colombia
Mensajes: 1.797
Antigüedad: 18 años, 11 meses
Puntos: 394
Respuesta: manejar script de login php

colocas el formulario:

Código HTML:
Ver original
  1. <form method="POST" name="form1" action="<?php echo $loginFormAction; ?>">
  2.     <table align="center">
  3.       <tr valign="baseline">
  4.         <td align="right" nowrap>Email:
  5.           <input name="Email" type="text" onblur="MM_validateForm('Email','','RisEmail');return document.MM_returnValue" value="" size="10" />
  6.           <input name="submit" type="submit" value="Ir" /></td>
  7.       </tr>
  8.     </table>
  9.     <input type="hidden" name="id_registrar" value="">
  10.     <input type="hidden" name="MM_insert" value="form1">
  11.   </form>
__________________
Por que existe gente que no agradece después de que se le ha brindado tiempo y ayuda ???
  #5 (permalink)  
Antiguo 18/04/2011, 08:35
Usuario no validado
 
Fecha de Ingreso: febrero-2008
Ubicación: Montevideo
Mensajes: 142
Antigüedad: 16 años, 2 meses
Puntos: 7
Respuesta: manejar script de login php

Cita:
Iniciado por cienporcientoweb Ver Mensaje
nuevamente Muchas gracias por responder tan rapido amigo..

disculpa mi ignorancia...



Graciassssss


Por suerte gente como tu existe para ayudar a gente como yo
(los que saben y los que quieren aprender)
  #6 (permalink)  
Antiguo 25/04/2011, 16:46
Usuario no validado
 
Fecha de Ingreso: febrero-2008
Ubicación: Montevideo
Mensajes: 142
Antigüedad: 16 años, 2 meses
Puntos: 7
Respuesta: manejar script de login php

Hola intente hacerlo de la forma que ustedes me dicen pero no me salio si alguien me puede decir como hacer o algun manual con el cual poder comprender mejor como crear la web, necesito ayuda

gracias

Etiquetas: login, manejar
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 14:04.