Hiya, Ive got a few websites that use sessions and I thought id upgrade them now to use cookies. In the main file it calls the session start function, and then this function is called, but it does not seem to work. I open a new window and the cookie does not seem to auto log me on.
Sorry if I have not explained it right, I want a feature like amazon where you go back to a site and you are still logged in. The test member has rememberpassword as y. The code below keeps my sessions but the cookie bit dosent work. Thanks, Steve XX /* Check a session is valid */ function session_check($db_link) { //Ok so either want to log on, or have a session or cookie allready if(isset($_SESSION['ssun']) || isset($_COKKIE["ssun"]) || isset($_POST['ssname'])) { //Attempt to logon. Set the logon form variables to the session variables. if(isset($_POST['sspass'])&&isset($_POST['ssname'])) { $_SESSION['sspw'] =$_POST['sspass']; $_SESSION['ssun'] =$_POST['ssname']; if(isset($_COOKIE["ssun"])) { $_COOKIE['ssun']=""; $_COOKIE["ssun"]=""; } } if(isset($_COOKIE["ssun"])) { $result = mysql_query("SELECT rememberpassword, memberid, title, lastname, lastnamenow, md5(memberpassword), email FROM members WHERE md5(memberpassword)='".$_COOKIE['sspw']."' AND email='".$_COOKIE['ssun']."'", $db_link); } else { //Check if the session username and password are correct $result = mysql_query("SELECT rememberpassword, memberid, title, lastname, lastnamenow, md5(memberpassword), email FROM members WHERE memberpassword='".$_SESSION['sspw']."' AND email='".$_SESSION['ssun']."'", $db_link); } if(mysql_num_rows($result)==1) { $loggedin="yes"; $userdata = mysql_fetch_row($result); if($userdata[0]=="y") { //Set up the cookies, store the md5 version of the password setcookie ("ssun", $userdata[6],time()+604800); setcookie ("sspw", $userdata[5],time()+604800); } if($userdata[4]=="") //If no last name now { $_SESSION['title']=$userdata[2]; $_SESSION['lastname']=$userdata[3]; } else //Use the last name now { $_SESSION['title']=$userdata[2]; $_SESSION['lastname']=$userdata[4]; } } else { $loggedin="no"; } if(isset($_GET['logoff'])) { if($_GET['logoff']=="true") { //Remove the session and cookies $loggedin="no"; $_SESSION['ssun']=""; $_SESSION['sspw']=""; $_SESSION['title']=""; $_SESSION['lastname']=""; setcookie ("ssun", "",time()-3600); setcookie ("sspw", "",time()-3600); } } return $loggedin; } else { return "no"; } } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php