require './cookie.lib';
require './sid.pl';

sub PonerCookie
{
	local($sid);
	local ($valid) = 0;

	if (&GetCookies('sid') && ( ! $ARGS{sid} || $ARGS{sid} == $Cookies{'sid'}))
	{
$globalError = $globalError."Paso 1 ";
		$valid = 1;
		$sid = $Cookies{'sid'};
	} elsif ( $ARGS{sid})
	{
$globalError = $globalError."Paso 2 ";
		$valid = 1;
		$sid = $ARGS{sid};
	}

	if ($valid)
	{
$globalError = $globalError."Paso 3 ";
		$sid_global = $sid;
                return 1;
	}

$globalError = $globalError."Paso 4 ";
	$sid=&GenerarSid();
	$sid_global = $sid;
	&SetCookiePath('/');
	&SetCookies('sid', "$sid");
        return 0;
}

sub Cookie
{
	print "Content-type: text/html\n";
        if (&PonerCookie() == 0)
	{
$globalError = $globalError."Paso 5 ";
		print "\n";
		PaginaInicio();
		exit 0;
	}
	print "\n";
}

1;
