|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2002-12-14 01:26 UTC] briantmeyer at earthlink dot com
On my IIS Server, now running 4.3.0RC3 ( i just installed
and tested it, started writing issue with RC2),
$_Server variables are not global, they don't work inside
functions
specifically $agent =?$_SERVER["HTTP_USER_AGENT"];
I hear that *nix machines do not have this issue.
The following does not work, there is no variable set for
the user agent and i get an error.
<?php
whatever();
function whatever()
{
$agent =?$_SERVER["HTTP_USER_AGENT"];
}
?>
Parse error: parse error, unexpected T_VARIABLE in c:\
inetpub\wwwroot\admin\index.php on line 26
PHP Parse error: parse error, unexpected T_VARIABLE in c:\
inetpub\wwwroot\admin\index.php on line 26
Basically the variable is not set.
This does work outside the function however
<?php
$agent = $_SERVER["HTTP_USER_AGENT"];
?>
(i coded this to explain issue more simply,
originally got help at
http://www.webmasterworld.com/forum13/1766.htm
which has more specific details, example code and the like)
$_SERVER["HTTP_USER_AGENT"]; is global in scope but is not
accessable in my installation inside a function.
I now use define to pass variable down to my function and
avoid any more issues personally.
I have a feeling it has to do with my using release
candidate 2 but do not wish to test with previous versions
of php at this time.
This seems like an IIS quirk as the forum moderator seemed
not to have this issue and agreed $_SERVER variables are
global in scope, as is my understanding from was what i
read in the manual.
info from my phpinfo()
PHP Version 4.3.0RC2
System Windows NT localhost 5.0 build 2195
Build Date Nov 27 2002 21:11:38
Server API CGI/FastCGI
register globals is also on for the time being, (seems like
this is always asked)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 03:00:02 2025 UTC |
Some thoughts: a) That error has nothing to do with undefined or "non global" variables. It's a parse error. b) Variables are case sensitive, never write $_Server it's ALWAYS $_SERVER c) A weird character? I really don't think this was ever an error in PHP and has to do with your code only, PHP won't put weird characters in your code. I blame your text editor. Try this test: <?php echo foo(); function foo() { return $_SERVER['HTTP_USER_AGENT']; } ?> What text editor do you use to write code?