Page 1 of 1

Superglobal Variable Problem

Posted: Sat Feb 03, 2007 3:57 pm
by audiac
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi, I've just begun working with PHP, and I've run into a problem displaying superglobal variables.  Here is the code I'm using:

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>superglobals</title>
	<meta http-equiv="Content-Type"
		content="text/html"; charset=utf-8" />
</head>

<body>

	<?php
		print "Your IP Address is: $_SERVER['REMOTE_ADDR'] <br />";
		print "Your browser is: $_SERVER['HTTP_USER_AGENT']";
	?>

</body>
</html>
When I open this file in my browser (Firefox), nothing at all is displayed, including the non-variable strings. Nothing at all appears in the browser. Yet if I run the phpinfo() function, all of the superglobal (among many others) variables display perfectly. I have tried using the 'echo' function instead - still I get the same result. I'm running Apache 2.2.4 and PHP 5.2.0, and I've tried this in both Firefox and IE. Any ideas, suggestions?


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Sat Feb 03, 2007 4:09 pm
by Ollie Saunders
Read the section of the manual on strings. Here's a hint:

Code: Select all

echo "Stuff from {$array['element']}";

Posted: Sat Feb 03, 2007 4:22 pm
by audiac
Thanks, this helped me get the variables to output correctly. Not sure why the book I'm working through gave the code the way it did, but I'm straightened out now. Thanks again.

Posted: Sat Feb 03, 2007 4:24 pm
by Ollie Saunders
does the title end in "for dummies" by any chance?

Posted: Sat Feb 03, 2007 4:36 pm
by audiac
The book was Beginning PHP and MySQL 5, by W. Jason Gilmore.

Posted: Sat Feb 03, 2007 5:26 pm
by superdezign
Jason Gilmore? Never heard of him. He's wrong. :-p

I mean, you can output certain variables that way, but I guess he thought he was too good to test first.

Re: Superglobal Variable Problem

Posted: Sat Feb 03, 2007 7:38 pm
by bokehman
audiac wrote:When I open this file in my browser (Firefox)
PHP file are not for opening with Firefox. They must be executed using the PHP interpreter.