Jump to content

Please help with sessions!


iNko

Recommended Posts

I got a log-in form with database, it only logs if such username and password exists. I was told that if i wanna make a log-out button once logged-in, i need to add sessions to my code and idk how..

 

this is my code that checks if username/password exists, and if so it lets u log in, if not it displays a msg:

if(isset($_POST['loginsubmit'])){
if($username !="" && $password !="") {


///////////////////////////////Check for username/pass in database////////////////////////////		
	$nameexists = false;
	$passexists = false;
	$result = pg_query("SELECT name FROM duom WHERE name='".$username."'");		
	while ($row = pg_fetch_array($result)) {
		if($row['name'] != ""){
			$nameexists = true;
		}
	} if($nameexists) {
		$result = pg_query("SELECT pass FROM duom WHERE name='".$username."'");
		while ($row = pg_fetch_array($result)) {
			if($row['pass'] == $password){
			$passexists = true;
			echo "Prisijungimas pavyko, jusu vartotojo vardas - ".$username."";
			include"loggedinform.php";
			} else {
				echo "Slaptazodis netinka!";
			}
/////////////////Starts session if password is correct////////////////////////////////////////////				
			if ($passexists){
			//Here i want it to start the session if password is correct
			}
//////////////////////////////////////////////////////////////////////////////////////////////////////////
		} 
	} else {
		echo "Tokio vartotojo nera!";
	}
//////////////////////////////////////////////////////////////////////////////////////////////////////////		


} else {
	echo "Uzpildykite visus duomenys!";
}
}

 

Cant i just make smth like this?

if ($passexists){
			session_start();
			}

Link to comment
https://forums.phpfreaks.com/topic/262195-please-help-with-sessions/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.