Programación php
Email: Password:


¡Regístrate gratis! | ¿Has perdido tu password?

Home
Blog

En él que podrás informarte de todas las noticias relacionadas con el posicionamiento de páginas web.

Ir al Blog de posicionamiento web



Foro de programación en PHP

Responder el mensaje

Ayuda con un código de sistema de login en php...

Autor: bronco_huguillo
Publicado: 02-4-2009 09:15 PM
Hola soy nuevo en estos menesteres del php [8)], me las ingenie para adaptar un sistema de login basado en php en un sitio web... la cosa es que al accesar con mis datos lo que deseo hacer es que en lugar de que me abra en la misma ventana la página a donde se accesa, quiero cambiar el código para que me de acceso a esa página en otra ventana (como si pusiera target="blank") y se conservara la página inicial intacta y a la vez tener la del acceso en una ventana nueva, no se si me explico... bueno aqui posteo mi codigo haber si me podrían echar la mano [;)]:


<?php
<?php

*/////////////// SISTEMA DE LOGEO PARA USUARIOS REGISTRADOS //////////////

*archivo con mis datos para entrar a la base de datos mysql:
require_once('Connections/modulatemedia.php');

* el chiste es que si entra a la pagina, pero el siguiente codigo es el que necesito modificar

?>
<?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['username'])) {
$loginUsername=$_POST['username'];
$password=md5($_POST['password']);
$MM_fldUserAuthorization = "";
$MM_redirectLoginSuccess = "espacio.php";
$MM_redirectLoginFailed = "index.php";
$MM_redirecttoReferrer = false;
mysql_select_db($database_modulatemedia, $modulatemedia);

$LoginRS__query=sprintf("SELECT username, password FROM users WHERE username=%s AND password=%s",
GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));

$LoginRS = mysql_query($LoginRS__query, $modulatemedia) 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 );
}
}
?>

.
.
.

* Mas abajo tengo una forma para accesar a la pagina

<form ACTION="<?php echo $loginFormAction;?>" id="form1" name="form1" method="POST">
<table width="499" border="0" height="20"align="center">
<tr>
<td width="60" height="20"><div align="right" class="style3" style="height:20"><strong>Usuario: </strong></div></td>
<td width="122" height="20"><input name="username" type="text" id="username" tabindex="1" maxlength="20" style="height:20" /></td>
<td width="86" height="15"><div align="right" class="style3" style="height:20"><strong>Contraseña :</strong></div></td>
<td width="120" height="20"><input name="password" type="password" id="password" tabindex="2" maxlength="20" style="height:20" /></td>
<td width="89" height="20"><input name="submit" type="submit" id="submit" tabindex="4" onClick="MM_validateForm('username','','R');MM_validateForm('password','','R');MM_validateForm('email','','RisEmail');return document.MM_returnValue" value=" Accesar " /></td>
</tr>
</table>
</form>



Bueno espero me puedan ayudar, muchas gracias [;)]
Autor: Fabricio
Publicado: 24-11-2009 12:38 PM
Espero todavia te sirva

Tienes que colocar en el inicio del script PHP (antes que nada)

if (!isset($_SESSION)) {
session_start();
}

luego si el resto del codigo

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": ……………………………………..
……………………………………………………...