Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

PHP Newbie Needs a Hand

  • 14-05-2002 12:22AM
    #1
    Registered Users, Registered Users 2 Posts: 1,783 ✭✭✭


    Hi,
    I just installed PHP so I'm a complete newbie to this. I have a problem already, I'm not sure if it's normal or not but perhaps one of ye guys can help me out.

    I'm trying out the Introductory Tutorial on PHP.net here --> http://www.php.net/tut.php and I've fallen at the second hurdle.

    I want to write the PHP script that produces the user's browser type. The tutorial at PHP.net says I should use this:
    [PHP]<?php echo $HTTP_USER_AGENT; ?>[/PHP]
    It seems to make sense but it doesn't work. I just get a blank page.

    So, in an effort to find out what the problem was, I went and made a script containing this code:
    [PHP]<?php phpinfo(); ?>[/PHP]
    This should have given me loads of info about PHP, which it did. I went looking for the variable $HTTP_USER_AGENT on that page but couldn't find it. Instead I found the variable $_SERVER["HTTP_USER_AGENT"] and used this in the script that I wanted to show the browser type.

    So now my script looks like this:
    [PHP]<?php echo $_SERVER["HTTP_USER_AGENT"]; ?>[/PHP]

    That did the job. But is this normal? Did they change the names of the variables and, therefor, is the tutorial I'm reading out of date or something?


Comments

  • Registered Users, Registered Users 2 Posts: 2,518 ✭✭✭Hecate


    you're not using php 4.2.0 by any chance?

    there have been quite a few changes from the last version, particularly in regard to accessing HTTP environment variables.


  • Closed Accounts Posts: 6,601 ✭✭✭Kali


    i presume you are using IIS.. it stores slightly different enviroment variables than apache.. in this case the user_agent is stored in the server_vars array.
    there should be a full list of variables in the IIS documentation..


  • Registered Users, Registered Users 2 Posts: 1,783 ✭✭✭Puck


    I'm using PHP 4.2.0 and Apache 1.3.24 on Win XP.


  • Banned (with Prison Access) Posts: 16,659 ✭✭✭✭dahamsta


    What Hecate said Puck. For security reasons, the developers have turned off automatic environment generation in the global environment and moved them into pseudo globals prefixed with _ instead. You can adjust the behaviour back to the old way, but as a new developer you're better off this way.

    adam


  • Registered Users, Registered Users 2 Posts: 1,783 ✭✭✭Puck


    Grand! That's me sorted so! :D
    Was just wondering if it was normal.
    Thanks everyone!:)


  • Advertisement
Advertisement