Include file for LOGIN.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

Oh I see, this file was being used by another application so I copied the file and placed it in my directory. maybe this is what is causing it. BUT so long as it exists in my directory how can this be a problem?
User avatar
bmcewan
Forum Commoner
Posts: 55
Joined: Wed Jun 02, 2004 7:19 am
Location: West Yorkshire, UK.

Post by bmcewan »

If the file perm.inc and the file that is calling it are in the same directory/folder then change you include to

Code: Select all

include "perm.inc";
using ../ in the path is making it look in the directory level above the current one
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

I really appreciate your time and help but can you explain that again.
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

I think I know what you mean. the last person to use this file kept his files in different directories which is why he had the ../ in my case the file is in the same directory so ill remove the ../ like you said. let me try that.
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

Ok ive tried this and now and I no longer get the error message or the blank screen.

BUt I was expecting a password prompt - this doesnt happen.

Then I thought I realised what happens. As I login to the system as a user who is already in the perm.inc file the system simply allows me to access the protected page without prompting for a username and password. I thought Id test this theory out by deleting myself from the perm.inc file and logging in again. as normal it let me log in to the system but also let me access the protected page so obviously this page is still not protected.

I dont really know where to go from here
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

Hi there,

I am now sure that my script is calling the include file as the echoed statement - "included file" appears on the blank screen.

Heres the script at the top of the page I want to protect.

Code: Select all

<?php

	include "perm.inc";
	if ( permcheck($REMOTE_USER,$ADMIN_USERS)) {
	  //Do nothing and carry on rendering the page
    }
    else {
	  header("Location: https://wwws.soi.city.ac.uk/intranet/plo/test/");
	  exit;
	}
?>



Heres the include file code


Code: Select all

<?php

$ADMIN_USERS = array ('chris','deger','pkogan','johnk','carol','renate','peter','bevr','sj368','npalmer','michell');



/* PHP4

echo "included file"; 

function permcheck ($user, $ValidUser) {
  while ( $a = array_shift($ValidUser))
    if ($user == $a) return 1;
	return 0;

}
*/

// PHP3 version

echo "included file"; 

function permcheck ($user,$ValidUser) {
  while (list ($k,$v) = each ($ValidUser) )
  if ($user == $v) return 1;
  return 0;
}
?>


This is the error message im now getting - cannot send header information headers already sent.......


Any help please especially the last guy who was helping me a lot.
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

I tested this information by removing my username from the Include file. This now works as when I added myself back to the include file it let me access the form. The only problem I can see now is with the header information.

I can see one way around this - it probably isnt working because of the confusing headers.

can I modify the 'else' statement to send the users to the following location
http://www.soi.city.ac.uk/organisation/ ... index.html

with a message saying You do not have admin rights please contact the administrator at top of the page.

Code: Select all

<?php

	include "perm.inc";
	if ( permcheck($REMOTE_USER,$ADMIN_USERS)) {
	  //Do nothing and carry on rendering the page
    }
    else {
	  header("Location: https://wwws.soi.city.ac.uk/intranet/plo/test/");
	  exit;
	}
?>
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Header information errors are most commonly associated with a) tying to set a cookie after output is sent to the browser; b) trying to start a session after output is sent the browser and there hasn't been a call to ob_start(); and c) trying to use the header() function after output is sent to the browser. In all cases, when using header information setting functions, DO NOT send anything to the browser before the call to the function.
Post Reply