Click to See Complete Forum and Search --> : PHP variables don't display
As seems to be the theme in these posts, I'm a newbie to PHP and just got it up and running with Apache/PHP4/Mysql on a 95 platform. Everything seems to be working great except that in my PHP scripts whenever I try to use a pre-defined variable such as $PHP_SELF or $HTTP_USER_AGENT in a printf statement or echo statement, they show up blank. No error, just nothing, not even a placeholder (ie. whatever follows starts right where the variable should supposedly print out.) Ideas anyone?
make sure you use echo or print and if you are using these variables in a function be sure to use...
global $PHP_SELF;
Disregard my first response. Edit your autoexec.bat file by going to start>run>sysedit>
type
SET PATH=%PATH%;"c:\your\php"
I tested your solution but it did not seem to work. However, I did find in the php.ini file some docutentation that helped me get it to work. This appears to be a PHP4 non-backward-compatibility issue as it says you now have to use getenv() or $HTTP_SERVER_VARS[] to get your variable.
echo getenv("HTTP_USER_AGENT");
echo $HTTP_SERVER_VARS["PHP_SELF"];
The above two lines of code worked on my system. It appears that if the variable is an environment variable, then use getenv(). If it is a server variable, use $HTTP_SERVER_VARS[]. THere is also a $HTTP_ENV_VARS[] but it did not work for me.
I understood from my reading that PHP4 was going through great pain to make it compatible with PHP3. Is this an example of the contrary or do I still just have something configured wrong on my system?
The text below is from php.net and there is a note about these variables when using the ISAPI version of php. If you are using the version then you have answer !
Thomas
string getenv (string varname)
Returns the value of the environment variable varname, or false on an error.
$ip = getenv ("REMOTE_ADDR"); // get the ip number of the user
You can see a list of all the environmental variables by using phpinfo(). You can find out what many of them mean by taking a look at the CGI specification, specifically the page on environmental variables.
Note: This function does not work in ISAPI mode.
I am developing php scripts on my windows 2000 box, and have had similar problems of variables not displaying along with no corresponding error message. Then, once I upload the identical script to the server- bingo - works like a charm - error messages and everything!
Anyhow, I Think I figured out the problem- the php executable I installed came with two separate php.ini files - a recommended on, and a distribution one - like most developers in a hurry, I selected the recomended one by default. Well, delving deeper into the issue one day, I discovered that the recommeded php.ini file had turned several debbugging options off and changed variable handling for security reasons etc... so... to make a super long story short - CHECK THE PHP.INI file.
Cheers
Hello can someone help me. I was reading what you were saying about he php ini file and I practically tried changing everything around but I still couldn't get my varibles to display.
Also, when I use the include("file.extension") using a variable and go to the page or whatever it dosn't work. I'm guessing its because I can't get my variables to change from one page to anothe like when I have a simple form I can't get anything to process on another page. Can someone help me with getting this thing fixed.
PHP Builder
Copyright Internet.com Inc. All Rights Reserved.