Ver Mensaje Individual
  #4 (permalink)  
Antiguo 08/05/2013, 15:36
Avatar de Jogabba
Jogabba
 
Fecha de Ingreso: octubre-2012
Mensajes: 18
Antigüedad: 12 años
Puntos: 0
Respuesta: Problema con sesión

Gracias, pero me gustaría comprender por qué no funciona mi código antes de usar otro.

Por cierto, la página de login es así:



Cita:
<?php

session_start();
if (isset($_POST['nick'])) {
//Connect to the database through our include
include ("PHP/connect_to_mysql.php");

$nick = $_POST['nick'];

$password = preg_replace("[^A-Za-z0-9]", "", $_POST['password']); // filter everything but numbers and letters
$password = md5($password);
// Make query and then register all database data that -
// cannot be changed by member into SESSION variables.
// Data that you want member to be able to change -
// should never be set into a SESSION variable.
$sql = mysql_query("SELECT * FROM members WHERE nick='$nick' AND password='$password' AND activacion='1'");
$login_check = mysql_num_rows($sql);
if($login_check > 0){
while($row = mysql_fetch_array($sql)){
// Get member ID into a session variable
$id = $row["id"];
$_SESSION['id'] = $id;

// Get member username into a session variable
$nick = $row["nick"];
$_SESSION['nick'] = $nick;

// Print success message here if all went well then exit the script
header("location: http://www.vacancesisortides.com/index.php");
exit();
} // close while
} else {
// Print login failure message to the user and link them back to your login page
print '<br /><br /><font color="#FF0000">No match in our records, try again </font><br />
<br /><a href="login.php">Click here</a> to go back to the login page.';
exit();
}
}// close if post
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Login to your profile</title>
<script type="text/javascript">
<!-- Form Validation -->
function validate_form ( ) {
valid = true;
if ( document.logform.email.value == "" ) {
alert ( "Please enter your User Name" );
valid = false;
}
if ( document.logform.pass.value == "" ) {
alert ( "Please enter your password" );
valid = false;
}
return valid;
}
<!-- Form Validation -->
</script>
</head>
<body>
<div align="center">
<h3><br />
<br />
Conéctate:<br />

<br />
</h3>
</div>
<table align="center" cellpadding="5">
<form action="http://www.vacancesisortides.com/login.php" method="post" enctype="multipart/form-data" name="logform" id="logform" onsubmit="return validate_form ( );">
<tr>
<td class="style7"><div align="right">Nick</div></td>
<td><input name="nick" type="text" id="nick" size="30" maxlength="64" /></td>
</tr>
<tr>
<td class="style7"><div align="right">Contraseñaa:</div></td>
<td><input name="password" type="password" id="password" size="30" maxlength="24" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input name="Submit" type="submit" value="Conectate" /></td>
</tr>
</form>
</table>
Si aún no estás registrado, hazlo <a href="http://www.vacancesisortides.com/registre.php">aquí.</a>
</body>
</html>

Última edición por Jogabba; 08/05/2013 a las 15:42