Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,546
    Thanks
    45
    Thanked 259 Times in 256 Posts

    _SERVER variables different among servers; any way to sync?

    Up till now, I've been doing development on a local WAMP server and had my sites hosted on a Dreamhost shared host. Recently, I've wanted to expand what technologies I have access to, so now I'm renting a VPS.

    I moved one of my projects over to see how well I've done (I still can't get the mail server working ). I pretty quickly noticed an issue: I use $_SERVER['REDIRECT_URL'] locally to get the current URL without any anchors or query strings on my local server, but noticed that I needed $_SERVER['SCRIPT_URL'] on my Dreamhost server. When I tried either on my new server, nether contains the data I want. I tried to do a var_dump($_SERVER) but there are no variables there that match what I want. I can use $_SERVER['REQUEST_URI'], but it contains the query string as well, so I'd have to separate that out somehow.

    Why are the SERVER variables different on each server? Is there something I can do to sync them up? I don't really understand what the difference is and why.

    I analyze the path to figure out what file to load (a custom dispatch system). Obviously this means that my code can't simply move between servers. It makes me think I'm doing something wrong given frameworks don't seem to have this issue...

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,682
    Thanks
    25
    Thanked 656 Times in 655 Posts
    I looked fin the manual PHP: $_SERVER - Manual and this was posted near the bottom of the page.

    searched $_SERVER["REDIRECT_URL"] for a while and noted that it is not mentioned in php documentation page itself. look like this is only generated by apache server(not others) and using $_SERVER["REQUEST_URI"] will be useful in some cases as mine.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #3
    Regular Coder
    Join Date
    Sep 2011
    Posts
    428
    Thanks
    18
    Thanked 26 Times in 26 Posts
    Just run a check on it. If it has one key, then use it. If it has another key, use it.

    Adapting across multi platforms is hard to learn since they're all different yet similar, and it takes more time and code to do, but it makes switching between systems a breeze and will save you time from going back and changing everything and whatnot.

  • #4
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,474
    Thanks
    63
    Thanked 537 Times in 524 Posts
    Depends on the webserver and OS.

    I've come a cropper with these minor glitches plenty of times. You kinda get used to them after a while..
    I can't really think of anything to write here now...

  • #5
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,470
    Thanks
    13
    Thanked 361 Times in 357 Posts
    Quote Originally Posted by Keleth View Post
    I can use $_SERVER['REQUEST_URI'], but it contains the query string as well, so I'd have to separate that out somehow.
    use parse_url() for that.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #6
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,546
    Thanks
    45
    Thanked 259 Times in 256 Posts
    Thanks for the responses. I more or less figured out how to get the URL, but I was more curious if anyone knew/understood why the variables change server to server, and if there's any way to sync them between servers.

  • #7
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,470
    Thanks
    13
    Thanked 361 Times in 357 Posts
    there is an explanation in the Manual:
    $_SERVER is an array containing information such as headers, paths, and script locations. The entries in this array are created by the web server. There is no guarantee that every web server will provide any of these; servers may omit some, or provide others not listed here. That said, a large number of these variables are accounted for in the CGI/1.1 specification, so you should be able to expect those.
    and hence it is not possible to sync different servers, since it is not the responsibility of PHP (alone) to create those variables.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •