View Full Version : $ don't display
wooki97
08-11-2002, 05:47 AM
I am just starting out in php. I got phpinfo to display. no problem. However, moving on I went thru some exercises in a beginner php book and I am stuck. The problem is I can't get $variable to display.
for ex in my php script
<?php
ECHO "<BR><B>Browser: </B> $HTTP_USER_AGENT";
?>
This is the result.
Browser:
The $ don't show. I tried using forms and have the variable- what the user type-in the text field display on another php script. By the same results. Nothing under the $
I am using Apache1.3.22
php4.2.2
How I installed. (cgi binary)
php.ini in windows/system
added script alias code in my conf file
Anyone who can help me is the master!
Christian
Newer versions of PHP default to having register globals set to off. That means the easy syntax of $HTTP_USER_AGENT doesn't work.
You'd need - either
$_SERVER['HTTP_USER_AGENT'];
or
$HTTP_SERVER_VARS['HTTP_USER_AGENT'];
I think.
wooki97
08-11-2002, 07:36 AM
try them but to no avail? Any other suggestion? Thanks
firepages
08-11-2002, 09:25 AM
some variables are not available to php running as a CGI - you would be better off (in lots of ways) to run PHP as a module.
that said, $_SERVER['HTTP_USER_AGENT']; or $HTTP_SERVER_VARS['HTTP_USER_AGENT']; as posted by Ökii should work regardless...
errr if PHP is indeed running I am unsure why this is occurring,
try this script and tell us what you get (if anything)
<?
while(list($key,$var)=each($HTTP_ENV_VARS)){echo "$key , $var<br>";}
?>
the CGI variables available to you should show up in there somewhere
wooki97
08-11-2002, 09:42 AM
COMSPEC , C:\\WINDOWS\\COMMAND.COM
DOCUMENT_ROOT , c:/apache group/apache/htdocs
HTTP_ACCEPT , image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*
HTTP_ACCEPT_CHARSET , iso-8859-1,*,utf-8
HTTP_ACCEPT_ENCODING , gzip
HTTP_ACCEPT_LANGUAGE , en
HTTP_CONNECTION , Keep-Alive
HTTP_HOST , localhost
HTTP_USER_AGENT , Mozilla/4.71 [en] (Win98; I)
PATH , C:\\WINDOWS;c:\\windows;c:\\windows\\COMMAND
REDIRECT_STATUS , 200
REDIRECT_URL , /lessons/test.php
REMOTE_ADDR , 127.0.0.1
REMOTE_PORT , 1763
SCRIPT_FILENAME , c:/php/php.exe
SERVER_ADDR , 127.0.0.1
SERVER_ADMIN , admin@norton.antivirus
SERVER_NAME , pop3.norton.antivirus
SERVER_PORT , 80
SERVER_SIGNATURE ,
Apache/1.3.22 Server at pop3.norton.antivirus Port 80
SERVER_SOFTWARE , Apache/1.3.22 (Win32)
WINDIR , C:\\WINDOWS
GATEWAY_INTERFACE , CGI/1.1
SERVER_PROTOCOL , HTTP/1.0
REQUEST_METHOD , GET
QUERY_STRING ,
REQUEST_URI , /lessons/test.php
SCRIPT_NAME , /php/php.exe
PATH_INFO , /lessons/test.php
PATH_TRANSLATED , c:\\apache group\\apache\\htdocs\\lessons\\test.php
ergo
$HTTP_ENV_VARS['HTTP_USER_AGENT'];
should do for you :)
firepages
08-11-2002, 09:49 AM
ok so "HTTP_USER_AGENT , Mozilla/4.71 [en] (Win98; I) " exists (get a decent browser please they are free ! ;))
so you are just going to have to use
<?echo $_ENV['HTTP_USER_AGENT'];?>
instead of $_SERVER etc & so I assume its a CGI-issue (get php as a module and change that browser :thumbsup: )
wooki97
08-11-2002, 10:55 AM
<FORM METHOD="POST" ACTION="p-4-1.php">
<H2>Contact List</H2>
<BR>Nickname:
<BR><INPUT TYPE="TEXT" NAME="Fullname">
<BR>Full name:
<BR><INPUT TYPE="TEXT" NAME="Fullname">
</form>
above code for html file
bottom code for php file
<?
echo "<BR>Nickname=$_['Nickname']";
echo "<BR>Fullname=$Fullname";
?>
I get this on browser.
Nickname=
Fullname=
Empty. Why?
firepages
08-11-2002, 11:01 AM
lol sorry Ökii - didnt see you there!
firepages
08-11-2002, 11:43 AM
<?
echo "<BR>Nickname=$_POST['Nickname']";
echo "<BR>Fullname=$_POST[Fullname]";
?>
+ your form code is wrong you have 2 'Fullname' fields
wooki97
08-11-2002, 11:59 AM
I get this from the code:
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or
T_NUM_STRING in c:\apache group\apache\htdocs\lessons\p-4-1.php on line 4
Now I am trying to install as a module instead.
when I open phpinfo.php to test on netscape.
I get this:
you have started to download a file of type application/x-httpd-php
What is a good browser to download?
firepages
08-11-2002, 12:32 PM
sorry my bad try this...
<?
echo "<BR>Nickname=".$_POST['Nickname'];
echo "<BR>Fullname=".$_POST['Fullname'];
?>
the browser wont affect how PHP renders , but I would suggest if you dont want to use IE that you pop over to mozilla .org and get the latest stable mozilla browser.
you are getting the download box because your apache config is not right, in your httpd.conf you need something like this...
LoadModule php4_module c:/php/sapi/php4apache.dll
AddType application/x-httpd-php .php4 .php .htm .php3
AddType application/x-httpd-php-source .phps
thats assuming php4apache.dll is in your sapi folder along with php4ts.dll which needs to be in sapi or /winnt/system32
+remove your old script-alias stuff
wooki97
08-11-2002, 02:09 PM
I copied and pasted your code to my conf file. I made sure the dlls are in my sapi. Can you tell me are if they are hidden files. Coz when I go to explorer I don't see the php4apache.dll but when I copy the file in the folder. An overwrite box pops up saying the file already exists. Weird.
I still get the download box when i open phpinfo.php! I try a html doc with 2 textboxs Action to p-10-1.php. Like above FullName and LastName. When I submit this message appeared
Method Not Allowed
The requested method POST is not allowed for the URL /lessons/p-10-1.php.
Apache/1.3.22 Server at pop3.norton.antivirus Port 80
Am I doing something wrong with install the module? I did not edit php.ini in my window/system. Am I supposed to?
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.