$_SERVER not working

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Puneet

    $_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?

  • Bent Stigsen

    #2
    Re: $_SERVER not working

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

    Sound like you need some curly brackets:

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

    --
    /Bent

    Comment

    • Puneet

      #3
      Re: $_SERVER not working

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

      PHP Notice: Undefined index: HTTP_HOST in C:\Program Files\Apache
      Group\Apache2\h tdocs\_debug_tm p.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:[color=blue]
      > Puneet wrote:
      > [snip][color=green]
      > > All the uper globals are not working. They
      > > just come back with e.g Array ['HTTP_HOST']... Can any body help?[/color]
      >
      > Sound like you need some curly brackets:
      >
      > echo "{$_SERVER['HTTP_HOST']}";
      >
      > --
      > /Bent[/color]

      Comment

      • ctclibby

        #4
        Re: $_SERVER not working


        Puneet wrote:[color=blue]
        > Nope.. If i use your code.. then I am getting this..
        >
        > PHP Notice: Undefined index: HTTP_HOST in C:\Program Files\Apache
        > Group\Apache2\h tdocs\_debug_tm p.php on line 5
        >
        >
        > If i use
        > Print "Host is : $_SERVER ['HTTP_HOST']";[/color]
        ............... ............... ..............^
        That a space between the SERVER and ['HTTP Oops, take it out.

        Comment

        • Bent Stigsen

          #5
          Re: $_SERVER not working

          Puneet wrote:
          [color=blue]
          > Nope.. If i use your code.. then I am getting this..
          >
          > PHP Notice: Undefined index: HTTP_HOST in C:\Program Files\Apache
          > Group\Apache2\h tdocs\_debug_tm p.php on line 5[/color]

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

          Perhaps you can use 'SERVER_NAME' instead.

          [color=blue]
          > If i use
          > Print "Host is : $_SERVER ['HTTP_HOST']";[/color]

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

          Since the index is not used, it just tells you that $_SERVER is an array.


          [snip]


          --
          /Bent

          PS: please don't top post

          Comment

          • Puneet

            #6
            Re: $_SERVER not working

            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:[color=blue]
            > Puneet wrote:
            >[color=green]
            > > Nope.. If i use your code.. then I am getting this..
            > >
            > > PHP Notice: Undefined index: HTTP_HOST in C:\Program Files\Apache
            > > Group\Apache2\h tdocs\_debug_tm p.php on line 5[/color]
            >
            > Then it is (probably) not present in the http-request. Blame your
            > browser/proxy.
            >
            > Perhaps you can use 'SERVER_NAME' instead.
            >
            >[color=green]
            > > If i use
            > > Print "Host is : $_SERVER ['HTTP_HOST']";[/color]
            >
            > Wouldn't work. When using an array inside an string, you will need the curly
            > brackets to tell PHP to use the index.
            >[color=green]
            > > The I am getting..
            > > Host is : Array ['HTTP_HOST'][/color]
            >
            > Since the index is not used, it just tells you that $_SERVER is an array.
            >
            >
            > [snip]
            >
            >
            > --
            > /Bent
            >
            > PS: please don't top post[/color]

            Comment

            • Jerry Stuckle

              #7
              Re: $_SERVER not working

              Puneet wrote:[color=blue]
              > 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.
              >
              >[/color]
              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.
              jstucklex@attgl obal.net
              =============== ===

              Comment

              • iavian

                #8
                Re: $_SERVER not working

                Not all browser sends HOST header ,, < HTTP/1.1

                Comment

                Working...