473,383 Members | 2,005 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

$_SERVER not working

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
7 9246
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
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

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
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
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
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
Not all browser sends HOST header ,, < HTTP/1.1

Jun 16 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: chops | last post by:
I need the path of the script that is running. Unfortunately it is not in the $_SERVER array when running a script through the CLI. Through a browser I can strip the script name off, e.g...
7
by: deko | last post by:
Why is $_SERVER returning multiple IP Addresses? Actually, I'm not sure if it's $_SERVER -- or which if/else statement -- that's the problem, but what I'm getting as a value for $visip looks...
4
by: CPD | last post by:
I can't parse $_SERVER when using the alphabetic key instead of the numeric index of the array. Below is some of the line-numbered code, followed by the corresponding output. For this posting, IP...
10
by: tHatDudeUK | last post by:
My form action code to submit values to itself have stopped working using the code form action = <?=$_SERVER?> This code used to work My web host recently told me they enabled phpsuexec...
1
by: Michael Brennan-White | last post by:
If I submit my for using a get action the resulting page loads . If I use a post action I get an error page saying "The page cannot be found". I am calling the originating page!!! This happens...
10
by: Jim Carlock | last post by:
Looking for a way to extract the path from the pfqpn (partially full qualified path name). $sThisServer = $_SERVER; // returns either aquaticcreationsnc.com or www.aquaticcreationsnc.com ...
4
by: Chris | last post by:
I'm working on a large intranet group site with a lot of pages, file types, folders, subfolders, etc. I am using the include ('../includes/file.php') , but I would like to have a single snippet...
2
by: Flava18 | last post by:
I recently switched servers and now my $_SERVER variables don't seem to be working - they simply just don't give anything back. I'm trying to use: $url = $_SERVER; Worked on my old server, but...
4
by: Ronald Raygun | last post by:
I have just discovered that the value reported for $_SERVER by phpinfo is different from the value I obtain when I run the following: <?php echo $_SERVER ?> My natural assumption is to assume...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.