Forum Moderators: coopster

Message Too Old, No Replies

Undefined variable _SERVER error

get this error trying to access any variables using $_SERVER

         

MX_OnD

12:56 pm on Aug 15, 2005 (gmt 0)

10+ Year Member



<?php

echo('<p>' . $_SERVER['PHP_SELF'] . '</p>');

?>

this is my code. Whenever I try to view it in the Browser I am getting the following error:

Warning: Undefined variable: _SERVER in c:\inetpub\wwwroot\phpincludes\includes\simpleParagraph.php on line 3

I'm pretty new at the whole PHP game, but I have tried finding answers on here already and at the sitepoint forums too with no joy, any pointers would be greatly appreciated.

jetboy

1:05 pm on Aug 15, 2005 (gmt 0)

10+ Year Member



Firstly, remove the spaces around the full stops and the brackets:

echo '<p>'.$_SERVER['PHP_SELF'].'</p>';

Does that work? If not, is your version of PHP later than 4.1.0? If not, try:

echo '<p>'.$HTTP_SERVER_VARS['PHP_SELF'].'</p>';

MX_OnD

1:24 pm on Aug 15, 2005 (gmt 0)

10+ Year Member



thanks jetboy!

my PHP version is 4.0.4 - I take it an upgrade is highly advisable?

using $HTTP_SERVER_VARS seems to have done it though, except when I want to get DOCUMENT_ROOT like this:

<?php
echo('<p>'.$HTTP_SERVER_VARS['PHP_SELF'].'</p>');
?>

This is giving me the following error:

Warning: Undefined index: DOCUMENT_ROOT in c:\inetpub\wwwroot\phpincludes\includes\simpleParagraph.php on line 3

any ideas?

JerryOdom

1:32 pm on Aug 15, 2005 (gmt 0)

10+ Year Member



looks like it should work fine. try using this

<?php
phpinfo();
?>

and seee if the server variable you're calling is defined in your php.

MX_OnD

1:51 pm on Aug 15, 2005 (gmt 0)

10+ Year Member



Cheers JerryOdom!

On a very generic note, please forgive my naivity...

How essential would it be to upgrade to PHP 5, in your considered opinion?

jatar_k

3:50 pm on Aug 15, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



it is not essential to go to php 5 either that or 4.4 would do.

I think the biggest advantage is the object oriented differences though there are a few functions that I like in php 5.

so if you do a ton of OOP scripts then 5 would be better, aside from that it doesn't matter but getting off of 4.0.4 is most definitely strongly advised.