Superglobal Variable Problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
audiac
Forum Newbie
Posts: 3
Joined: Sat Feb 03, 2007 3:39 pm

Superglobal Variable Problem

Post 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]
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Read the section of the manual on strings. Here's a hint:

Code: Select all

echo "Stuff from {$array['element']}";
audiac
Forum Newbie
Posts: 3
Joined: Sat Feb 03, 2007 3:39 pm

Post 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.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

does the title end in "for dummies" by any chance?
audiac
Forum Newbie
Posts: 3
Joined: Sat Feb 03, 2007 3:39 pm

Post by audiac »

The book was Beginning PHP and MySQL 5, by W. Jason Gilmore.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post 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.
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Re: Superglobal Variable Problem

Post 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.
Post Reply