Location: PHPKode > projects > PhpMyDVDs > phpmydvds/session.php
<?php

    /***************************************************************************
                                 session.php  -  description
                                -------------------

        copyright          : (C) 2002 by Cédric Rochat
        email                : hide@address.com
    ***************************************************************************/
    /***************************************************************************
    *
    *   This program is free software; you can redistribute it and/or modify
    *   it under the terms of the GNU General Public License as published by
    *   the Free Software Foundation; either version 2 of the License, or
    *   (at your option) any later version.
    *
    ***************************************************************************/

    require ("util.php");

	function CreerSession ($connexion, $password, $IDSession)
	{
		require ("config.php");

		if (md5($password)==$admin_pwd)
		{
			$maintenant = date ("U");
			// Session active pour une heure
			$TempsLimite = $maintenant+3600;

			$insSession = "INSERT INTO $pTable_Prefixe"."Session (IDSession, TempsLimite) VALUES ('$IDSession', '$TempsLimite')";
			$resultat = ExecRequete ($insSession, BASE);

			session_register ("Internaute");
			return TRUE;
		}
		return FALSE;
	}

	function DetruireSession ($IDSession)
	{
		require ("config.php");

		$connexion = Connexion (NOM, PASSE, BASE, SERVEUR);
		$maintenant = date ("U");
		session_destroy();

		$requete = "DELETE FROM $pTable_Prefixe"."Session WHERE IDSession='$IDSession'";
		$resultat = ExecRequete ($requete, BASE);

		// Nettoyage des anciennes sessions abandonnées par un internaute
		$requete = "DELETE FROM $pTable_Prefixe"."Session WHERE TempsLimite < '$maintenant'";
		$resultat = ExecRequete ($requete, BASE);
	}

	function ProlongerSession ($IDSession)
	{
		require ("config.php");

		$connexion = Connexion (NOM, PASSE, BASE, SERVEUR);
		$maintenant = date ("U");

		$Prolongation=$TempsLimiteAdmin*60;

		$TempsLimite=$maintenant+$Prolongation;

		$requete = "UPDATE $pTable_Prefixe"."Session SET TempsLimite='$TempsLimite' WHERE IDSession='$IDSession'";
		$resultat = ExecRequete ($requete, BASE);

		// Nettoyage des anciennes sessions abandonnées par un internaute
		$requete = "DELETE FROM $pTable_Prefixe"."Session WHERE TempsLimite < '$maintenant'";
		$resultat = ExecRequete ($requete, BASE);
	}

	function SessionValide ($connexion, $session)
	{
		require ("config.php");

		$maintenant = date ("U");
		if ($session->TempsLimite < $maintenant)
		{
			session_destroy();

			$requete = "DELETE FROM $pTable_Prefixe"."Session WHERE IDSession='$session->IDSession'";
			$resultat = ExecRequete ($requete, BASE);

			// Nettoyage des anciennes sessions abandonnées par un internaute
			$requete = "DELETE FROM $pTable_Prefixe"."Session WHERE TempsLimite < '$maintenant'";
			$resultat = ExecRequete ($requete, BASE);

			return FALSE;
		}
		else
		{
			ProlongerSession($session->IDSession);
			return TRUE;
		}
	}

	function ControleAcces ($password, &$Internaute, $IDSession)
	{
		require ("config.php");

		$connexion = Connexion (NOM, PASSE, BASE, SERVEUR);
		$SessionCourante = ChercheSession ($IDSession, $connexion);

		if (is_object ($SessionCourante))
		{
			if (SessionValide ($connexion, $SessionCourante))
			{
				$Internaute=$IDSession;
				return TRUE;
			}
			else return FALSE;
		}

		if (isset($password))
		{
			if (CreerSession ($connexion, $password, $IDSession))
			{
				$Internaute=$IDSession;
				return TRUE;
			}
			else return FALSE;
		}
	}

?>
Return current item: PhpMyDVDs