Jump to content

issue with if clause and includes


h20boynz

Recommended Posts

Hi there

 

I'm banging my head against a wall and could really use some advice.... :confused:

 

I am trying to include on a page one of two include files based on a simple criteria.

<?php
if (!isset($loginok)){
          include $_SERVER['DOCUMENT_ROOT'] . '/phpscripts/login.home.php';
} else {
          include $_SERVER['DOCUMENT_ROOT'] . '/phpscripts/logout.home.php';
}
?>

In another file I set $GLOBAL['loginok'] = 'Logged in';

(The other file checks for user name in DB etc)

And after logging out I use unset($GLOBALS['loginok']);

 

But no matter what state the $loginok value is in it will only show one of the include files.

 

I've tried using $_SESSION variables that are set as well because I know they are se,t but they have the same result.

The files login.home.php and logout.home.php are two little forms for display on the index.php page. I use seperate login.php page if a user navigates to a page that they are required to be logged in for.  This all works well.

I just want to show a logout button on the home page or a login box on the home page based on the users state...very fustrating :)

 

Link to comment
https://forums.phpfreaks.com/topic/199878-issue-with-if-clause-and-includes/
Share on other sites

It's set in access.php

 

if (databasecontainsuser($_POST['username'], $password))
{
	session_start();
	$_SESSION['loggedin'] = TRUE;
	$_SESSION['username'] = $_POST['username'];
	$_SESSION['password'] = $password;
	$GLOBALS['loginok'] = 'Logged in';
	return TRUE;
} else {
	session_start();
	unset($_SESSION['loggedin']);
	unset($_SESSION['username']);
	unset($_SESSION['password']);
	$GLOBALS['loginerror'] = 'The specified user or password was incorrect.' . $email . $password;
	return FALSE;
	}
	$password = md5($_POST['password'] . 'xxxx');
}

I've tried using isset on the $_SESSION variable above too but it has the same effect.

Thanks

 

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.