<?php
/*
乘风下载管理系统
作者QQ：178575
作者Email：yliangcf@163.com
作者网站：http://www.qqcf.com
详细简介：http://www.qqcf.com/cfdown.htm
上面有程序在线演示，安装演示，使用疑难解答，最新版本下载等内容
因为这些内容可能时常更新，就没有放在程序里，请自己上网站查看
*/
?>
<?php 
//--用户
$cfdownusercookie=Chkstr($_COOKIE["cfdownusercookie"],1);
if(!isset($_SESSION['cfdownuser']))
{
  if($cfdownusercookie!='')
  {
	$Sql="Select username From cfdown_user where usercode='$cfdownusercookie'";

	$Result=mysql_query($Sql);
	if($Rs=mysql_fetch_assoc($Result))
		$_SESSION['cfdownuser']=$Rs["username"];
	else
		unset($_COOKIE["cfdownusercookie"]);
  }
}

if($_SESSION["cfdownuser"]!="" && $cfdownusercookie=="")//Session存在但cookie不存在时，重新写Cookie
{
	$Sql="Select usercode From cfdown_user Where username='".$_SESSION["cfdownuser"]."'";

	$Result=mysql_query($Sql);
	if($Rs=mysql_fetch_assoc($Result))
	 setcookie("cfdownusercookie",$Rs['usercode'],time()+3600,"/");
	else
	 unset($_SESSION["cfdownuser"]);

}



//--管理员
$cfdownadmincookie=Chkstr($_COOKIE["cfdownadmincookie"],1);
if(!isset($_SESSION['cfdownadmin']))
{
  if($cfdownadmincookie!='')
  {
	$Sql="Select adminusername,admincode From cfdown_adminuser where admincode='$cfdownadmincookie'";

	$Result=mysql_query($Sql);
	if($Rs=mysql_fetch_assoc($Result))
		$_SESSION['cfdownadmin']=$Rs["adminusername"];
	else
		unset($_COOKIE["cfdownadmincookie"]);
  }
}

if($_SESSION["cfdownadmin"]!="" && $cfdownadmincookie=="")//Session存在但cookie不存在时，重新写Cookie
{
	$Sql="Select admincode From cfdown_adminuser Where adminusername='".$_SESSION["cfdownadmin"]."'";

	$Result=mysql_query($Sql);
	if($Rs=mysql_fetch_assoc($Result))
	 setcookie("cfdownadmincookie",$Rs['admincode'],time()+3600,"/");
	else
	 unset($_SESSION["cfdownadmin"]);
}

