Sticking with your theme of doing this login system with sessions here's something that works, but is far from bulletproof. You also need something to go clearing all the dead sessions out of the database when they're too old. Either throw in the extra delete query when you check the database, or set up something on a cron job.
This would be your validador5.php
<?
session_start();
//$conn = mysql_connect("mysql.gestionar.info","aa1126","huissen");
$conn= mysql_connect();
//mysql_select_db("aa3968",$conn);
mysql_select_db("test", $conn);
$Inmo=@$_REQUEST['Inmo'];
$Password=@$_REQUEST['Password'];
$sessid=session_id();
$ssql = "SELECT * FROM Clientes WHERE Inmo='$Inmo' and Password='$Password'";
$rs = mysql_query($ssql,$conn);
if (mysql_num_rows($rs)!=0)
{
$_SESSION['autentificado']="SI";
$Fecha = date("Y-d-m h:i:s");
//Use replace instead of INSERT, million to one chance you're going over
//somebody elses session but I don't case, it gets rid of the error if
//the session is currently in there
$sql = "REPLACE Sesiones ( Fecha, Sesion, Inmo)" .
"VALUES ('$Fecha', '$sessid', '$Inmo')";
$result = mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');
header ("Location: check_page.php");
}
else
{ //Clear out DB, session and Go back to Login
$query="DELETE from Sesiones WHERE Sesion='$sessid'";
mysql_query($query, $conn);
session_destroy();
header("Location: login.htm");
}
mysql_free_result($rs);
mysql_close($conn);
?>
Then in each of your pages that needs to check just use the function in this. This is check_page.php
<?php
if ( check_session() )
{
//show page stuff here
echo "YOU ARE LOGGED IN!";
}
else
{
//they are not logged in
echo "YOU ARE NOT LOOGGED IN";
}
function check_session()
{
session_start();
if ( isset( $_SESSION['autentificado'] ) )
{
//$conn = mysql_connect("mysql.gestionar.info","aa1126","huissen");
$conn=mysql_connect() or DIE("NO CONNECT");
//mysql_select_db("aa3968",$conn);
mysql_select_db("test", $conn) or DIE("NO SELECTIO");
$sessid=session_id();
$ssql = "SELECT * FROM Sesiones WHERE sesion='$sessid'";
$rs = mysql_query($ssql,$conn) OR die("QUERY CRAssP".mysql_error() );
if ( mysql_num_rows($rs) !=0 )
{
$row=mysql_fetch_assoc($rs);
//check date against login timeout ELSE return 0
if( $row['Fecha'] ) // DO some date calculation on this
{
return 1;
}
else
{
$query="DELETE from Sesiones WHERE Sesion='$sessid'";
mysql_query($query, $conn);
}
}
}
session_destroy();
return 0;
}
?>