PDA

View Full Version : Next to suicide: sessions


Elhombrebala
11-05-2003, 05:42 PM
Can anybody tell me where's the fu%#@~~ error?
Whenever I execute it get lost, it does not find validador5.php!!!
3 pages:
1- Form (acceso5.html):

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Documento sin título</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<div align="center">
<p> </p>
<p> </p>
<p> </p>
<p>
<FORM action="validador5.php" method="POST">
Usuario
<input name="Inmo" type="text" id="Inmo">
<br>
Password
<input name="Password" type="password" id="Password">
<br>
<input type="submit" name="Submit" value="Enviar">
</FORM>
</p>
</div>
</body>
</html>


2 - Asking some datas and opening a Session in php (validador5.php):

<?
session_register('usuario');
?>
<?
//conecto con la base de datos
$conn = mysql_connect("mysql.gestionar.info","aa1126","huissen");
//selecciono la BBDD
mysql_select_db("aa3968",$conn);
//Sentencia SQL para buscar un usuario con esos datos
$ssql = "SELECT * FROM Clientes WHERE Inmo='$Inmo' and Password='$Password'";

//Ejecuto la sentencia
$rs = mysql_query($ssql,$conn);

//vemos si el usuario y contraseña es váildo
//si la ejecución de la sentencia SQL nos da algún resultado
//es que si que existe esa conbinación usuario/contraseña
if (mysql_num_rows($rs)!=0){
//usuario y contraseña válidos
//defino una sesion y guardo datos
session_start();
session_register("autentificado");
$autentificado = "SI";
$Sesion=session_id();
$Sesioname=session_name();
$Bothsesiones=$Sesioname."=".$Sesion;
$Fecha = date("Y-d-m h:i:s");
$sql = "INSERT INTO Sesiones ( Fecha, Sesion, Inmo)" .
"VALUES ('$Fecha', '$Sesion', '$Inmo')";
$result = mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');
header ("Location: uploader5.html?$Bothsesiones");
}else {
//si no existe le mando otra vez a la portada
header("Location: acceso5.html?errorusuario=si");
}
mysql_free_result($rs);
mysql_close($conn);
?>

3- The last document (where we suposely wanted to arrived ask if session is seted (uploader5.html):

<?PHP
if (isset($_SESSION['sessionname'])) {
echo "Usuario reconocido";
}
else {
header ("Location: acceso5.php");
}
?>

EnwTheGood
11-05-2003, 08:28 PM
In validor5.php, move the session_start(); command before any session_register commands. Make sure there is no whitespace before the opening <? tag, and try to remove the ?><? in there, just for good measure if nothing else.

Hope this helps!

-Me

DCElliott
11-06-2003, 05:09 AM
I don't use php in any of my pages but have dabbled a bit. Doesn't a php sequence start:
<?php

Joe the Large
11-06-2003, 05:26 AM
Normally it does start with <?php but if the server has short tags enabled, you can start with just <? .

Elhombrebala
11-06-2003, 08:18 AM
There's something I can not understand, does session not change any time I start new session?
Have any sense to do this?


PHP:
--------------------------------------------------------------------------------

<?
session_start();
if (isset($_SESSION['sesionname'])) {
echo "Usuario reconocido";
}
else {
header ("Location: acceso5.php");
}
?>

--------------------------------------------------------------------------------


If I pass via URL the session name and id to next page and in next page I start session, how can I ask for old session started??
By the way, I did today what you suggested me yesterday and (I agree, I'm stupid) but it doesn't work.
What I have now:
1 Form in first page, it doesn't change from yesterday:
(Everyone is invited to go there and check the problem it gives)
www.costa4seasons.com/acceso5.html
2 Php to validate password:

PHP:
--------------------------------------------------------------------------------

<?
//conecto con la base de datos
$conn = mysql_connect("mysql.gestionar.info","aa1126","huissen");
//selecciono la BBDD
mysql_select_db("aa3968",$conn);
//Sentencia SQL para buscar un usuario con esos datos
$ssql = "SELECT * FROM Clientes WHERE Inmo='$Inmo' and Password='$Password'";

//Ejecuto la sentencia
$rs = mysql_query($ssql,$conn);

//vemos si el usuario y contraseña es váildo
//si la ejecución de la sentencia SQL nos da algún resultado
//es que si que existe esa conbinación usuario/contraseña
if (mysql_num_rows($rs)!=0){
//usuario y contraseña válidos
//defino una sesion y guardo datos
$_SESSION['autentificado']="SI";
$Sesion=session_id();
$Sesioname=session_name();
$Bothsesiones=$Sesioname."=".$Sesion;
$_SESSION['sesionname']=$sesioname;
$Fecha = date("Y-d-m h:i:s");
$sql = "INSERT INTO Sesiones ( Fecha, Sesion, Inmo)" .
"VALUES ('$Fecha', '$Sesion', '$Inmo')";
$result = mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');
header ("Location: uploader5.html?$Bothsesiones");
}else {
//si no existe le mando otra vez a la portada
header("Location: acceso5.html?errorusuario=si");
}
mysql_free_result($rs);
mysql_close($conn);
?>

--------------------------------------------------------------------------------


3- And finally, the destiny page that checks if session is set.

PHP:
--------------------------------------------------------------------------------

<?PHP
session_start();
if (isset($_SESSION['sesionname'])) {
echo "Usuario reconocido";
}
else {
header ("Location: acceso5.php");
}
?>

--------------------------------------------------------------------------------

User: Laclau
Pass: 435567

__________________

EnwTheGood
11-06-2003, 09:01 PM
You don't need to send the name or ID through the URL - the session_start command just restarts the session if one exists. Don't forget to add that command to the top of the page with the validation script.

Also, you seen to have acceso5.html and acceso5.php mixed up a bit. I would suggest naming all of your pages on a PHP-enabled website with .php.