Jump to content

[SOLVED] Predefined Variable not working as expected


scottybwoy

Recommended Posts

Hi guru's,

 

I have a script that was working fine until I had to reinstall everything.  Now my scripts says that :

 

PHP Notice: Undefined index: LOGON_USER in D:\Inetpub\wwwroot\name.php on line 5

 

Where I have just made a new file to isolate the issue, but this derives from this script :

 

<?php

echo $_SERVER['LOGON_USER'];

?>

 

Which worked fine before.  Is this down to the way php is being run? As it stands it is being run via IIS 5 as cgi executable.  I've looked over the install txt and it seems as though I have done everything correct.

Link to comment
Share on other sites

This does not depend on the way php is being run but depends on the php configuration. More specifically, you need to check the error_reporting option in php.ini. Probably you had notices disabled in your previous configuration and have them enabled in the new one. Just change the value of error_reporting so as to disable notices and restart IIS server so that the changes reflect in online applications.

Link to comment
Share on other sites

don't turn off error reporting...

 

your error is just saying that you want to print something to the browser that doesn't have a value yet...

 

<?php
        if(isset($_SESSION['LOGON_USER'])){
                echo $_SESSION['LOGON_USER'] ."<br />\n";
        }else{
                echo "SESSION LOGON USER has no value";
        }
?>

 

you claim that it is pre-defined. php doesn't think so. that's basically what's going on.

Link to comment
Share on other sites

Yes, you are correct.  I was not planning to turn off error reporting and have not.  Maybe I should make this a little clearer as boo_lolly got mixed up with $_SERVER & $_SESSION, I am using windows 2k environment and to my understanding $_SERVER['LOGON_USER'] Should display the current username logged on to Windows environment, however this is returning null.

 

I thought it may be down to the way it was executed as in the manual it suggests this predefined variable works differently under different environments, (no surprises there).  However I am using the same version of IIS and php with the same phi.ini config file and same scripts as before yet it is not working as before.

 

Can anyone spot the hole from the info I have given so far.

 

The IIS Box is also acting as DHCP+DNS server running active directory too if that helps.

 

Thanks for your time and input.

Link to comment
Share on other sites

oh damn, it must still be too early... sorry for the misunderstanding man... i don't know what i was/wasn't thinking =).

 

try doing this:

<?php
        echo "<pre>". print_r($_SERVER) ."</pre>\n";
        echo "<pre>". print_r($_ENV) ."</pre>\n";
?>

 

and see what you get.

Link to comment
Share on other sites

Yep now we are on the right trail.  As expected LOGON_USER is not available in the $_SERVER array.

 

What else should I be looking for?  Here are some results that may be useful :

 

[CONTENT_LENGTH] => 0

[GATEWAY_INTERFACE] => CGI/1.1

[HTTPS] => off

[HTTP_ACCEPT] => */*

[HTTP_ACCEPT_LANGUAGE] => en-gb

[HTTP_CONNECTION] => Keep-Alive

[HTTP_USER_AGENT] => Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727)

[HTTP_COOKIE] => debug_port=10013; debug_host=192.168.0.22; start_debug=1; debug_stop=1; send_sess_end=1; debug_jit=1;

[HTTP_ACCEPT_ENCODING] => gzip, deflate

[iNSTANCE_ID] => 1

[NUMBER_OF_PROCESSORS] => 2

[Os2LibPath] => D:\WINNT\system32\os2\dll;

[OS] => Windows_NT

[Path] => D:\WINNT\system32;D:\WINNT;D:\WINNT\System32\Wbem;D:\php;D:\Program Files\Microsoft SQL Server\80\Tools\Binn\;D:\Program Files\Microsoft SQL Server\90\Tools\binn\

[PATHEXT] => .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH

[PROCESSOR_ARCHITECTURE] => x86

[PROCESSOR_IDENTIFIER] => x86 Family 15 Model 4 Stepping 1, GenuineIntel

[PROCESSOR_LEVEL] => 15

[PROCESSOR_REVISION] => 0401

[ProgramFiles] => D:\Program Files

[REMOTE_ADDR] => 192.168.0.7

[REMOTE_HOST] => 192.168.0.7

[REQUEST_METHOD] => GET

[sCRIPT_NAME] => /name.php

[sERVER_PORT] => 80

[sERVER_PORT_SECURE] => 0

[sERVER_PROTOCOL] => HTTP/1.1

[sERVER_SOFTWARE] => Microsoft-IIS/5.0

[ORIG_PATH_INFO] => /name.php

[ORIG_SCRIPT_NAME] => /name.php

[php_SELF] => /name.php

[REQUEST_TIME] => 1176799554

 

What I found peculiar is that the debug host is 192.168.0.22 which is neither the servers ip nor my pc (192.168.0.7 <- dynamically assigned) and HTTP_USER_AGENT is Mozilla/4.0 although I loaded it via IE6.1?

 

Also $_ENV array returned empty, could this be part of the cause?

Link to comment
Share on other sites

from the manual http://us2.php.net/manual/en/reserved.variables.php

There is no guarantee that every web server will provide any of these; servers may omit some, or provide others not listed here.

 

my guess was that it has something to do with your windows box, and not your php.ini configuration. i did a little research and came up with these possible solutions:

 

1. enable Windows NTLM authentication in the PHP pages and use >PHP call GetEnv("LOGON_USER");

 

2. You should also be able to find your username stored in an environment variable on this page, normally in something like $_SERVER["AUTH_USER"] or $_SERVER["LOGON_USER"], which you can access from your PHP scripts (assuming you followed the steps to disable anonymous access in IIS). you should be able to check this by executing phpinfo(); and looking under the 'Environment' values.

 

http://hostlibrary.com/Building-a-PHP-5-Web-Server-on-Windows-IIS-web-hosting-.html

 

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.