By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,745 Members | 1,873 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,745 IT Pros & Developers. It's quick & easy.

$_SERVER not working

P: n/a
I really loosing sleep over this one. I have php 4.4 running on Apache
2.... php works fine. phpinfo() retuns everything as it should..
However when I try to print anything using $_SERVER e.g $_SERVER
['HTTP_HOST']... it returns nothing. Then I realized that even $_GET
and $_POST are not working. All the uper globals are not working. They
just come back with e.g Array ['HTTP_HOST']... Can any body help?

Jun 15 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Puneet wrote:
[snip]
All the uper globals are not working. They
just come back with e.g Array ['HTTP_HOST']... Can any body help?


Sound like you need some curly brackets:

echo "{$_SERVER['HTTP_HOST']}";

--
/Bent
Jun 15 '06 #2

P: n/a
Nope.. If i use your code.. then I am getting this..

PHP Notice: Undefined index: HTTP_HOST in C:\Program Files\Apache
Group\Apache2\htdocs\_debug_tmp.php on line 5
If i use
Print "Host is : $_SERVER ['HTTP_HOST']";

The I am getting..
Host is : Array ['HTTP_HOST']

What's wrong...
Please help...

Bent Stigsen wrote:
Puneet wrote:
[snip]
All the uper globals are not working. They
just come back with e.g Array ['HTTP_HOST']... Can any body help?


Sound like you need some curly brackets:

echo "{$_SERVER['HTTP_HOST']}";

--
/Bent


Jun 16 '06 #3

P: n/a

Puneet wrote:
Nope.. If i use your code.. then I am getting this..

PHP Notice: Undefined index: HTTP_HOST in C:\Program Files\Apache
Group\Apache2\htdocs\_debug_tmp.php on line 5
If i use
Print "Host is : $_SERVER ['HTTP_HOST']";

............................................^
That a space between the SERVER and ['HTTP Oops, take it out.

Jun 16 '06 #4

P: n/a
Puneet wrote:
Nope.. If i use your code.. then I am getting this..

PHP Notice: Undefined index: HTTP_HOST in C:\Program Files\Apache
Group\Apache2\htdocs\_debug_tmp.php on line 5
Then it is (probably) not present in the http-request. Blame your
browser/proxy.

Perhaps you can use 'SERVER_NAME' instead.

If i use
Print "Host is : $_SERVER ['HTTP_HOST']";
Wouldn't work. When using an array inside an string, you will need the curly
brackets to tell PHP to use the index.
The I am getting..
Host is : Array ['HTTP_HOST']


Since the index is not used, it just tells you that $_SERVER is an array.
[snip]
--
/Bent

PS: please don't top post

Jun 16 '06 #5

P: n/a
Thanx Bent... That helped..
I rewrote the code as :-
print "Host port is :". $_SERVER ['SERVER_PORT'] ;

and it worked...

There has to be a space between SERVER and [.. otherwise PHP throws an
exception.

Bent Stigsen wrote:
Puneet wrote:
Nope.. If i use your code.. then I am getting this..

PHP Notice: Undefined index: HTTP_HOST in C:\Program Files\Apache
Group\Apache2\htdocs\_debug_tmp.php on line 5


Then it is (probably) not present in the http-request. Blame your
browser/proxy.

Perhaps you can use 'SERVER_NAME' instead.

If i use
Print "Host is : $_SERVER ['HTTP_HOST']";


Wouldn't work. When using an array inside an string, you will need the curly
brackets to tell PHP to use the index.
The I am getting..
Host is : Array ['HTTP_HOST']


Since the index is not used, it just tells you that $_SERVER is an array.
[snip]
--
/Bent

PS: please don't top post


Jun 16 '06 #6

P: n/a
Puneet wrote:
Thanx Bent... That helped..
I rewrote the code as :-
print "Host port is :". $_SERVER ['SERVER_PORT'] ;

and it worked...

There has to be a space between SERVER and [.. otherwise PHP throws an
exception.

Not on any system I've ever used. The space is optional.

However - if you don't have the curly braces around it, I can see where PHP
might get confused.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jun 16 '06 #7

P: n/a
Not all browser sends HOST header ,, < HTTP/1.1

Jun 16 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.