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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.