Si lo he sacado precisamente de ahi, pero mi problema es que la sesion cada x tiempo peta, y no tengo nidea de porqué. Pego el codigo y a ver si alguien me puede ayudar.
Código PHP:
session_start();
// Function that registers a user
// This function should be called when a login is performed.
// Returns true if the user was logged in, false otherwise.
function registerUser($username,$password) {
require "phpauthent_config.php";
// Connect to the database and checks if the user / password
// combinaison matches any existing database entry
$mysql_link = mysql_connect($db_hostname,$db_username,$db_password) or die("Failed to connect to MySQL");
mysql_select_db($db_database, $mysql_link) or die ("Unable to select database!");
$query = "SELECT ".$db_fld_users_id." FROM ".$db_tbl_users." WHERE ".$db_fld_users_username." LIKE '".$username."' AND ".$db_fld_users_password." LIKE '".encrypt($password,$phpauthent_enckey)."'";
// $r_query = mysql_query($query, $mysql_link);// or mysql_error() and die("Failed to execute_query");
$r_query = mysql_query($query, $mysql_link) or die("Failed to execute_query");
if (mysql_num_rows($r_query) != 0) {
$query_row = mysql_fetch_array($r_query);
writeSessionUserIds($query_row[$db_fld_users_id], $username);
// Writing connection date into database
writeUserLoginDate($query_row[$db_fld_users_id]);
// Increasing number of connections for this user
writeUserConnection($query_row[$db_fld_users_id]);
// CREAMOS LA COOKIE PARA LA CONEXION
$valor=mysql_num_rows($r_query);
if (isset($session_lifetime)){
setcookie("frikysoft", $valor, time()+$session_lifetime);
}
else {
setcookie("frikysoft", $valor, time()+60);
}
return true;
exit;
} else {
return false;
exit;
}
}
Este de ahora es donde indico el tiempo de la cookie, que la he creado yo, pero creo que no lo creo bien, porque pasa un poco de mi.
Código PHP:
if (isset($session_lifetime)) {
session_set_cookie_params($session_lifetime);
}
else {
session_set_cookie_params(0);
}