Jump to content

sessions effecting $_POST??


ale1981

Recommended Posts

PHP 5.2.6

Apache 2.2.9

 

I am trying to store windows username / domain / workstation details into a session for our company intranet. I found a script on the internet that I can use to retrieve the information which I made into a function;

 

function get_user_details() {

// loune 25/3/2006, updated 22/08/2009
// For more information see:
// http://siphon9.net/loune/2007/10/simple-lightweight-ntlm-in-php/
// 
// This script is obsolete, you should see
// http://siphon9.net/loune/2009/09/ntlm-authentication-in-php-now-with-ntlmv2-hash-checking/
//

// NTLM specs http://davenport.sourceforge.net/ntlm.html

$headers = apache_request_headers();

if (!isset($headers['Authorization'])){
	header('HTTP/1.1 401 Unauthorized');
	header('WWW-Authenticate: NTLM');
	exit;
}

$auth = $headers['Authorization'];

if (substr($auth,0,5) == 'NTLM ') {
	$msg = base64_decode(substr($auth, 5));
	if (substr($msg, 0,  != "NTLMSSP\x00")
		die('error header not recognised');

	if ($msg[8] == "\x01") {
		$msg2 = "NTLMSSP\x00\x02\x00\x00\x00".
			"\x00\x00\x00\x00". // target name len/alloc
			"\x00\x00\x00\x00". // target name offset
			"\x01\x02\x81\x00". // flags
			"\x00\x00\x00\x00\x00\x00\x00\x00". // challenge
			"\x00\x00\x00\x00\x00\x00\x00\x00". // context
			"\x00\x00\x00\x00\x00\x00\x00\x00"; // target info len/alloc/offset

		header('HTTP/1.1 401 Unauthorized');
		header('WWW-Authenticate: NTLM '.trim(base64_encode($msg2)));
		exit;
	}
	else if ($msg[8] == "\x03") {
		function get_msg_str($msg, $start, $unicode = true) {
			$len = (ord($msg[$start+1]) * 256) + ord($msg[$start]);
			$off = (ord($msg[$start+5]) * 256) + ord($msg[$start+4]);
			if ($unicode)
				return str_replace("\0", '', substr($msg, $off, $len));
			else
				return substr($msg, $off, $len);
		}
		$user = get_msg_str($msg, 36);
		$domain = get_msg_str($msg, 28);
		$workstation = get_msg_str($msg, 44);

                       	session_start();
		$_SESSION['username'] = $user;
		$_SESSION['domain'] = $domain;
		$_SESSION['workstation'] = $workstation;
	}
}
}

 

What i would like to do is store the information in a session so I can access the information without having to call the function on every page. I have a header.php file which is called on each page, so in this file i have added;

 

require_once 'functions.php';
session_id();
session_start();
if (!$_SESSION['username']) {
    get_user_details();
}

 

This works, but seems to be breaking certain pages that retrieve $_POST details but I can not figure out why??

 

I have tried to work it out for the past 3 days but cant seem to get it to work, any help would be greatly appreciated!  :shrug:

Link to comment
Share on other sites

New update!

 

I think it is something in the function affecting $_POST.

 

I have removed the function call and tried to create a session and everything seems to work, what in the function could be affecting the $_POST details, could it be the header calls?

Link to comment
Share on other sites

Hi BlueSky

 

I have since amended the files, i have removed session_id() and the second instance of session_start() in the function.

I used the session_save_path to make sure the session files were being created.

 

With more testing, if I call the function get_user_details() every time in the header.php file then $_POST works fine, however if i only call it once to store the user details then $_POST doesnt work!? Is it something inside the function that is authenticating?

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.