hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : Newbie question: php environment variables undefined
Reply

Forum Jump

Newbie question: php environment variables undefined

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 08-30-2002, 11:17 PM
xor xor is offline
Newbie
 
Join Date: Jul 2001
Location: New Zealand
Posts: 28
Question

Newbie question: php environment variables undefined


I hope this is just a dumb newbie question with an easy solution/explanation...

I'm a ColdFusion developer who is now learning PHP and I'm having a bit of a problem. Any advice is appreciated.

I've got PHP installed and running (W2K, IIS5), I can call phpinfo() and all the variables display just fine. But when I write code to try to display some of the same variables I get the following error message:

Notice: Undefined variable: HTTP_USER_AGENT in D:\wwwroot\FB3Dev\test.php on line 14

Well, that is my script alright. The code I am using is:

<?php
echo $HTTP_USER_AGENT;
?>

I'm getting this out of tutorials I've printed from the net, and quadruple-checking my syntax. I can't see what I'm doing wrong. I've also tried with other variables such as $SCRIPT_NAME and $PHP_SELF, with similar results. I'm able to successfully set and display the value of other variables, it just seems to have a problem with the built-in variables, but the odd thing is that phpinfo() gives me the right result!

Any ideas/suggestions?

__________________
The New Zealand Site
http://www.thenewzealandsite.com



Sponsored Links
  #2  
Old 08-31-2002, 05:50 AM
Rich2k Rich2k is offline
Web Hosting Master
 
Join Date: May 2002
Location: UK
Posts: 2,994
I don't know what version of PHP you are using but in the most recent (with Register_globals disabled) those methods of calling the environment variables have been changed.

Now they are in arrays.

E.g. to get HTTP_USER_AGENT use

PHP Code:
$_SERVER['HTTP_USER_AGENT'
More details are on the PHP site
http://www.php.net/manual/en/languag...predefined.php

  #3  
Old 09-01-2002, 02:48 AM
xor xor is offline
Newbie
 
Join Date: Jul 2001
Location: New Zealand
Posts: 28
Thumbs up beautiful! that's exactly what it was!

Thanks Rich2k!
That is exactly what the problem was.

This must pose quite an upgrade problem for existing php sites migrating to the latest version if they have, for instance, used forms with the action page pointing to the form page using $PHP_SELF.

But this is so good to know because it could be a real "gotcha" if I were to use a host running a slightly older version of php.

__________________
The New Zealand Site
http://www.thenewzealandsite.com

Sponsored Links
  #4  
Old 09-01-2002, 11:44 PM
JustinH JustinH is offline
Web Hosting Master
 
Join Date: Nov 2000
Posts: 3,042
this is why I never rarely use predefined variables in my script. Or set all of them I need at the top of the page . Eventually things like this change, which is why it is SO important to write good code (and use comments).

__________________
A well-reasoned assumption is very close to fact.
- Adorno


  #5  
Old 09-02-2002, 04:44 AM
xor xor is offline
Newbie
 
Join Date: Jul 2001
Location: New Zealand
Posts: 28
Quote:
Originally posted by comphosting
this is why I never rarely use predefined variables in my script. Or set all of them I need at the top of the page . Eventually things like this change, which is why it is SO important to write good code (and use comments).
I couldn't agree more! I've been using Fusebox2 methodology with my ColdFusion coding and now I am learning PHP and Fusebox3. That's how I ran into the problem with the predefined variables. As you say they are definitely something to put into the app_globals (or whatever it's equivalent in FuseBox3) file in fusebox-speak, ie a top-level file that gets included into all the others.

__________________
The New Zealand Site
http://www.thenewzealandsite.com

  #6  
Old 09-09-2002, 09:03 AM
Rich2k Rich2k is offline
Web Hosting Master
 
Join Date: May 2002
Location: UK
Posts: 2,994
I tend to use an include function in which I set the variables I am likely to use into my own array. That way you only ever need to change one file if the language changes.

Reply

Related posts from TheWhir.com
Title Type Date Posted
Microsoft and AT&T Partnership Adds VPN to Windows Azure Web Hosting News 2013-09-20 10:39:32
The Value of Your Intellectual Property Blog 2013-05-06 17:43:13
Cloud Converter Launches Free Service for Migrating Cloud Servers Web Hosting News 2013-03-19 11:23:45
SoftLayer - Right on Schedule - My Estimate $2.5 billion Blog 2013-03-19 05:45:58
Joomla Hosting Study Shows Speed, Uptime Top Selling Points of a Web Host Web Hosting News 2012-11-07 15:06:36


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?