Jump to content

Login Help Using Sessions


clanstyles

Recommended Posts

<?php
require_once("class.query.php");
require_once("class.forms.php");
require_once("functions.php");

class user {
var $username = "";
var $password = "";
var $email = "";
var $status = 0;

####################
#	Check to see if 
#	a user is logged in.
function isLoggedin() {
	if(isset($_SESSION['username']) && isset($_SESSION['password']))
		return true;
	return false;
}

###################
# Auto Login Check
function checkLogin($username, $password) {
	$sql= new mysqlQuery();
	$sql->mysqlQuery();
	$sqlerror = "select * from users where username='$username' and password='$password' LIMIT 1";
	$results = $sql->query($sqlerror) ? "true" : "false";

	if($results)
	{
		$array = $sql->fetch_array($sqlerror);
		$this->username = $username;
		$this->password = $password;
		$_SESSION['username'] = $username;
		$_SESSION['password'] = $password;
		$_SESSION['email'] = $array['3'];
	}
	$sql->close();
}


##################
# Build Login Form
function buildLogin() {

	if (isset($_POST['username']) && isset($_POST['password']))
			$this->checkLogin(cleanstring($_POST['username']), cleanstring($_POST['password']));
	if(!$this->isLoggedin())
	{

			$forms = new forms();
		$forms->createFormBlank("login");
		$forms->createTextBoxAdv("Username: ", "username", 12, "if (this.value == '') { this.value = 'Username'; }", "if (this.value == 'Username') { this.value = ''; }", "", "Username", "0");
		echo "<br />\n";
		$forms->createTextBoxAdv("Password: ", "password", 12, "if (this.value == '') { this.value = 'Password'; }", "if (this.value == 'Password') { this.value = ''; }", "", "Password", "1");
		echo "<br />\n";		
		$forms->createSubmit("submit", "submit");
		$forms->endForm();

	}

}
}
?>

All the information is being obtained correctly. I have echoed it there isno problem there. The problem lies with it not saving the login info.

 

<?php
session_start();
date_default_timezone_set("Etc/GMT-5");
require_once("includes/class.user.php");
$user = new user();
if($user->isLoggedin())
{
	echo "<a href\"".session_destroy()."\">Logout</a>";
	echo date("h:i:s", time());
}
else
	$user->buildLogin();
?>

Link to comment
Share on other sites

if($user->isLoggedin())

{

echo "<a href\"".session_destroy()."\">Logout</a>";

echo date("h:i:s", time());

}

 

I didn't even read all the obdc, but you can't make a link to a php function that will actually run session_destroy and place its return in the echo (which is nothing)  You need to link to a separate page that has session_destroy in it. as a function.

Link to comment
Share on other sites

No one is going to help you if you can't even explain the problem right, you  obviously don't realize what your own code does if it is yours.

First off, it is mine, I don't understand why sometimes it THINKS i'm logged in and other times it doesn't The $user->isLoggedin() triggers randomly. letting you knowif you are logged in or not.

 

If you test it you will see. Sometimes, you login, sometimes your logged out. Reguardless if  you have the correct information. It does know to check.

 

 

Sorry for not supplying the correct informatin. I though I had explained it perfectly. But I guess not.

 

 

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.