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
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

 

Link to comment
Share on other sites

And is access.php included into your original script?

 

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

 

Did you have session_start() before trying to use the $_SESSION array?

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.