Jump to content

Recommended Posts

this is php 5, windows xp pro, apache

see the script below, responds to a basic form:

<html>

<body>

Welcome <?php echo $_POST["name"]; ?> <br />

You are <?php echo $_POST["age"]; ?> years old.

<?

echo "$_server request_uri = " . $_SERVER['REQUEST_URI']. "<br />";

echo "$_server request_uri = " . $_SERVER['SERVER_SOFTWARE']. "<br />";

?>

</body>

</html>

 

i get the response below, on the one hand its giving an error but its also seems to be displaying the $_server variable info?? not sure what to make of that:

 

Welcome bob

You are 58 years old.

 

Notice: Undefined variable: _server in C:\apache2\htdocs\1614\php\php1.php on line 15

request_uri = /php/php1.php

 

Notice: Undefined variable: _server in C:\apache2\htdocs\1614\php\php1.php on line 16

request_uri = Apache/2.2.4 (Win32) PHP/5.2.1 mod_aspdotnet/2.2

 

Link to comment
https://forums.phpfreaks.com/topic/129496-newbie-_server-question/
Share on other sites

Heehee, awpti read again!

 

remember double quotes are parsed.. singles are not.. so change to singles will work

<?php
echo '$_server request_uri = ' . $_SERVER['REQUEST_URI']. "<br />";
echo '$_server request_uri = ' . $_SERVER['SERVER_SOFTWARE']. "<br />";
?>

 

$_server isn't set yet PHP is attempting to parser it.. thus getting blank..

as you don't want this use single quotes

 

EDIT: you could also escape them ie

echo "\$_server request_uri = " . $_SERVER['REQUEST_URI']. "<br />";

thanks for the help

 

so resolving occurs when using dble quote vs single, thats kinda a convenience where you

can have vars resolved within a literal text string, saving having to concatenate, yes?

or is there other reasons for the parsing difference between dble and single?

bob

A single quote is a literal quote.  Anything inside will not be parsed by php and the output is exactly what is in the quote.

 

It will also let you do things like:

echo '<a href="http://somesite.com">Some Site</a>';

as opposed to:

echo "<a href=\"http://somesite.com\">Some Site</a>";

(even double quotes are taken as literal so you don't have to escape them)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.