Knuckles Posted March 25, 2013 Share Posted March 25, 2013 Hello, I have made a logout script with a existing login script i already had. Now when i try to logging it doesnt do anything anymore. I attached the login and logout.php. logout.php login.php Quote Link to comment https://forums.phpfreaks.com/topic/276120-login-and-logout/ Share on other sites More sharing options...
DaveyK Posted March 25, 2013 Share Posted March 25, 2013 (edited) Post the relevant code in code tags rather than posting the files, please. Edited March 25, 2013 by DaveyK Quote Link to comment https://forums.phpfreaks.com/topic/276120-login-and-logout/#findComment-1420902 Share on other sites More sharing options...
Knuckles Posted March 25, 2013 Author Share Posted March 25, 2013 (edited) There you go. Logout.php <?php if(isset($_COOKIE['cookie_name']) { unset($_COOKIE['cookie_name']); setcookie('key', '', time() - 3600); } header("Location: http://test.com"); ?> Login.php <?php class login { private $init, $db, $cookie = 'cookie_name'; function login( $init ) { $this->init = $init; $this->db = $init->getDB(); $this->alreadyLogged(); } function alreadyLogged() { if(isset($_COOKIE[$this->cookie]) && count(explode(';', base64_decode($_COOKIE[$this->cookie]))) > 3) { $url = base64_decode($_COOKIE[$this->cookie]); if($this->getCookieInformation( $url )) { header("Location: http://test.test.com"); } else { $this->clearCookie(); } } elseif( isset($_SESSION['login']['SESSIONID'],$_SESSION['login']['FUNCTIE'] ) ) { $row = $this->db->getQfa( $this->db->getQuery("SELECT COUNT(*) as Total FROM Laatst_ingelogd WHERE SessieID = ". mysql_escape_string($_SESSION['login']['SESSIONID'])) ); if($row[0]['Total'] > 0) { header("Location: http://test.test.com"); } } } function getCookieInformation( $base ) { $val = $this->getSessieQuery( $base ); if(mysql_num_rows($val) > 0 && $this->getLoginCredentials() !== NULL) return true; elseif( mysql_num_rows($val) > 0 ) { $row = $this->db->getQfa( $val ); $this->setLoginCredentials( $row[0]['SessieID'], $row[0]['Functie'] ); return true; } else return false; } function getSessieQuery( $base ) { list($SessieID, $GebruikerID, $Laatst_ingelogd, $IP) = explode(';', $base); return $this->db->getQuery(" SELECT li.SessieID, g.Functie FROM Laatst_ingelogd li INNER JOIN Gebruiker g ON li.GebruikerID = g.GebruikerID WHERE li.SessieID = ".mysql_escape_string($SessieID)." AND li.GebruikerID = ".mysql_escape_string($GebruikerID)." AND li.Laatst_ingelogd = '".mysql_escape_string($Laatst_ingelogd)."' AND li.IP = '".mysql_escape_string($IP)."' LIMIT 1"); } function userExists() { if($_POST) { if(isset($_POST['emaillogin']) && strlen($_POST['emaillogin']) > 5 && isset($_POST['password']) && strlen($_POST['password']) > 3) { $sql = sprintf("SELECT GebruikerID FROM Gebruiker WHERE Email = '".mysql_escape_string($_POST['emaillogin'])."' AND Wachtwoord = '".mysql_escape_string(General::encryptPassword( $_POST['password'] ))."' LIMIT 1"); $query = $this->db->getQuery($sql ); if(mysql_num_rows($query) > 0) return true; else return false; } else return false; } else return false; } function userInformation() { $val = $this->db->getQfa( $this->db->getQuery("SELECT GebruikerID, Functie FROM Gebruiker WHERE Email = '".mysql_escape_string($_POST['emaillogin'])."' AND Wachtwoord = '".mysql_escape_string(General::encryptPassword( $_POST['password'] ))."' LIMIT 1") ); return array($val[0]['GebruikerID'], $val[0]['Functie']); } function userLastLogin( $GebruikerID ) { $ip = $_SERVER['REMOTE_ADDR']; $timenow = date("Y-m-d H:i:s"); $this->db->getQuery("INSERT INTO Laatst_ingelogd (GebruikerID, Laatst_ingelogd, IP) VALUES (".$GebruikerID.", '".$timenow."', '".$ip."')"); return array($this->db->getLastID(), $timenow, $ip); } function setLoginCredentials( $sessie, $Functie ) { $_SESSION['login']['SESSIONID'] = $sessie; $_SESSION['login']['FUNCTIE'] = $Functie; } function getLoginCredentials() { if(isset($_SESSION['login']['SESSIONID'], $_SESSION['login']['FUNCTIE'])) return array( $_SESSION['login']['SESSIONID'], $_SESSION['login']['FUNCTIE'] ); else return NULL; } function setCookie( $GebruikerID, $Functie ) { list($SessieID,$Laatst_ingelogd,$IP) = $this->userLastLogin( $GebruikerID ); $encoded = base64_encode( $SessieID.';'.$GebruikerID.';'.$Laatst_ingelogd.';'.$IP ); $howlong = time() + 126144000; //4 years setcookie( $this->cookie, $encoded, $howlong, '/'); $this->setLoginCredentials( $SessieID, $Functie ); } function clearCookie() { $howlong = time() - 126144000; //4 years setcookie( 'cookie_name', "", $howlong); } function justlogin() { if($this->userExists()) { list($GebruikerID, $Functie) = $this->userInformation(); list($SessieID,$Laatst_ingelogd,$IP) = $this->userLastLogin( $GebruikerID ); $this->setLoginCredentials( $SessieID, $Functie ); return true; } else return false; } function keepLoggedin() { if($this->userExists()) { list($GebruikerID, $Functie) = $this->userInformation(); $this->setCookie( $GebruikerID, $Functie ); return true; } else return false; } } /* $this->setAssign('errEmail', ''); $this->setAssign('errPassword', ''); $login = new login( $this ); if($_POST) { if(isset($_POST['keeploggedin']) && $_POST['keeploggedin'] == 1) { if($login->keepLoggedin()){ header("Location: http://test.test.com"); } else { $this->setAssign('errEmail', 'rood'); $this->setAssign('errPassword', 'rood'); } } else { if($login->justlogin()) { header("Location: http://test.test.com"); } else { $this->setAssign('errEmail', 'rood'); $this->setAssign('errPassword', 'rood'); } } }*/ ?> Edited March 25, 2013 by Knuckles Quote Link to comment https://forums.phpfreaks.com/topic/276120-login-and-logout/#findComment-1420904 Share on other sites More sharing options...
trq Posted March 25, 2013 Share Posted March 25, 2013 Your going to need to at least attempt to narrow your issue down somewhat. Posting a bunch of code and saying "this doesn't work" does nothing to help us help you. Quote Link to comment https://forums.phpfreaks.com/topic/276120-login-and-logout/#findComment-1420906 Share on other sites More sharing options...
Knuckles Posted March 25, 2013 Author Share Posted March 25, 2013 The issue im having is that if i enter the login details and try to log in it refreshes the same page instead of going to another page. As i put in the code its suppose to go to test.test.com instead of coming back in test.com. Not sure if this helps anything Quote Link to comment https://forums.phpfreaks.com/topic/276120-login-and-logout/#findComment-1420921 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.