php-general Digest 20 Feb 2005 21:48:40 -0000 Issue 3297

Topics (messages 209077 through 209091):

php5 and globals?
        209077 by: Mike
        209078 by: M. Sokolewicz
        209079 by: Guillermo Nouche

[NEWBIE] Confused about usage of $_SERVER['DOCUMENT_ROOT']
        209080 by: Dave
        209081 by: Mirco Blitz
        209082 by: b1nary Developement Team
        209083 by: Andre Dubuc
        209084 by: Dave
        209085 by: John Nichel
        209086 by: b1nary Developement Team

[NEWBIE] Cant  get $_POST to work
        209087 by: David Freedman
        209089 by: John Nichel
        209090 by: b1nary Developement Team

Handling of partially completed forms
        209088 by: Joseph E. Maxwell
        209091 by: b1nary Developement Team

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---

I have read that php5 does something different with global_vars. I know that
many of my clients rely on them working. Will thinks start breaking after I
upgrade from 4.3.10 to 5.3?

TIA

--- End Message ---
--- Begin Message ---
Mike wrote:


I have read that php5 does something different with global_vars. I know that many of my clients rely on them working. Will thinks start breaking after I upgrade from 4.3.10 to 5.3?

TIA
"something different" being...? maybe you mean register_globals? that change goes back to php 4.2.0, but they're not planning to remove it from php anytime soon, due to the fact that so many people still rely on it
--- End Message ---
--- Begin Message ---
On Sun, 20 Feb 2005 15:14:27 +0100, M. Sokolewicz <[EMAIL PROTECTED]> wrote:
> Mike wrote:
> 
> >
> > I have read that php5 does something different with global_vars. I know that
> > many of my clients rely on them working. Will thinks start breaking after I
> > upgrade from 4.3.10 to 5.3?
> >
> > TIA
> "something different" being...? maybe you mean register_globals? that
> change goes back to php 4.2.0, but they're not planning to remove it
> from php anytime soon, due to the fact that so many people still rely on it
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 

Now objects are global always, and always references. Is that the
change you read?


Good luck,
-Guillermo

--- End Message ---
--- Begin Message ---
PHP General,

The Situation:
I would like to be able to specify locations of scripts and files relative to the "root" directory from which my web site is served. I thought this was what $_SERVER['DOCUMENT_ROOT'] was for.


The Problem:
When I use $_SERVER['DOCUMENT_ROOT'], it creates a path starting from somewhere deep down in the server's file structure, below where I even have authorized access. So if I specify a file like so:
$imageFile = $_SERVER['DOCUMENT_ROOT'] . "/images/image.jpg";
... PHP gets lost and doesn't locate it.
What I am looking for is a variable which will specify the base directory that my web site is rooted in. In other words, starting from the same directory that my index.html file is in.


The Question:
How do I specify the directory that my web site is situated in, the same directory where my main index.html file is? Is there a different variable I should be using, or perhaps some configuration of $_SERVER['DOCUMENT_ROOT'] that needs to be applied?


What I've Tried So Far:
First I went to the on line PHP manual, which is where I found out about $_SERVER['DOCUMENT_ROOT'] in the first place. Of all the server variables available, 'DOCUMENT_ROOT' seems to describe what I'm looking for, but doesn't behave how I would expect.
A Google search was equally ineffective in educating me in what basic concept I am missing.


   Any advice would be much appreciated.

--
Dave Gutteridge
[EMAIL PROTECTED]

--- End Message ---
--- Begin Message ---
Hi,

what does echo $imageFile print and what do you do afterwards with it.
Probably there is the error.

Mit freundlichen Gr��en
Mirco Blitz

-----Urspr�ngliche Nachricht-----
Von: Dave [mailto:[EMAIL PROTECTED] 
Gesendet: Sonntag, 20. Februar 2005 18:15
An: php-general
Betreff: [PHP] [NEWBIE] Confused about usage of $_SERVER['DOCUMENT_ROOT']

PHP General,

    The Situation:
    I would like to be able to specify locations of scripts and files
relative to the "root" directory from which my web site is served. I thought
this was what $_SERVER['DOCUMENT_ROOT'] was for.

    The Problem:
    When I use $_SERVER['DOCUMENT_ROOT'], it creates a path starting from
somewhere deep down in the server's file structure, below where I even have
authorized access. So if I specify a file like so:
    $imageFile = $_SERVER['DOCUMENT_ROOT'] . "/images/image.jpg";
    ... PHP gets lost and doesn't locate it.
    What I am looking for is a variable which will specify the base
directory that my web site is rooted in. In other words, starting from the
same directory that my index.html file is in.

    The Question:
    How do I specify the directory that my web site is situated in, the same
directory where my main index.html file is? Is there a different variable I
should be using, or perhaps some configuration of $_SERVER['DOCUMENT_ROOT']
that needs to be applied?

    What I've Tried So Far:
    First I went to the on line PHP manual, which is where I found out about
$_SERVER['DOCUMENT_ROOT'] in the first place. Of all the server variables
available, 'DOCUMENT_ROOT' seems to describe what I'm looking for, but
doesn't behave how I would expect.
    A Google search was equally ineffective in educating me in what basic
concept I am missing.

    Any advice would be much appreciated.

--
Dave Gutteridge
[EMAIL PROTECTED]

--
PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
http://www.php.net/unsub.php

--- End Message ---
--- Begin Message --- What's Up Dave... yeah, regardless of how deep this goes into the servers file structure, it should pull out the same thing in the end. Please print out the response and let us know what happens.

Dave wrote:

PHP General,

The Situation:
I would like to be able to specify locations of scripts and files relative to the "root" directory from which my web site is served. I thought this was what $_SERVER['DOCUMENT_ROOT'] was for.


The Problem:
When I use $_SERVER['DOCUMENT_ROOT'], it creates a path starting from somewhere deep down in the server's file structure, below where I even have authorized access. So if I specify a file like so:
$imageFile = $_SERVER['DOCUMENT_ROOT'] . "/images/image.jpg";
... PHP gets lost and doesn't locate it.
What I am looking for is a variable which will specify the base directory that my web site is rooted in. In other words, starting from the same directory that my index.html file is in.


The Question:
How do I specify the directory that my web site is situated in, the same directory where my main index.html file is? Is there a different variable I should be using, or perhaps some configuration of $_SERVER['DOCUMENT_ROOT'] that needs to be applied?


What I've Tried So Far:
First I went to the on line PHP manual, which is where I found out about $_SERVER['DOCUMENT_ROOT'] in the first place. Of all the server variables available, 'DOCUMENT_ROOT' seems to describe what I'm looking for, but doesn't behave how I would expect.
A Google search was equally ineffective in educating me in what basic concept I am missing.


   Any advice would be much appreciated.


--- End Message ---
--- Begin Message ---
On Sunday 20 February 2005 12:15 pm, Dave wrote:
> PHP General,
>
>     The Situation:
>     I would like to be able to specify locations of scripts and files
> relative to the "root" directory from which my web site is served. I
> thought this was what $_SERVER['DOCUMENT_ROOT'] was for.
>
>     The Problem:
>     When I use $_SERVER['DOCUMENT_ROOT'], it creates a path starting
> from somewhere deep down in the server's file structure, below where I
> even have authorized access. So if I specify a file like so:
>     $imageFile = $_SERVER['DOCUMENT_ROOT'] . "/images/image.jpg";
>     ... PHP gets lost and doesn't locate it.
>     What I am looking for is a variable which will specify the base
> directory that my web site is rooted in. In other words, starting from
> the same directory that my index.html file is in.
>
>     The Question:
>     How do I specify the directory that my web site is situated in, the
> same directory where my main index.html file is? Is there a different
> variable I should be using, or perhaps some configuration of
> $_SERVER['DOCUMENT_ROOT'] that needs to be applied?
>
>     What I've Tried So Far:
>     First I went to the on line PHP manual, which is where I found out
> about $_SERVER['DOCUMENT_ROOT'] in the first place. Of all the server
> variables available, 'DOCUMENT_ROOT' seems to describe what I'm looking
> for, but doesn't behave how I would expect.
>     A Google search was equally ineffective in educating me in what
> basic concept I am missing.
>
>     Any advice would be much appreciated.
>
> --
> Dave Gutteridge
> [EMAIL PROTECTED]


Hi Dave,

Perhaps what you should do to set $imageFile = "/images/image.jpg"
since I would assume, whatever your Document_Root is, 'images' is a 
sub-directory to it.

I.e.: if your servable document directory is something like 
"/vhome/tokyocomedy/all_your_files_are_here"
then
"/vhome/tokyocomedy/all_your_files_are_here/images/image.jpg" is where your 
image.jpg file is.

Also, check using <?php phpinfo(); ?> where the $_SERVER['DOCUMENT_ROOT'] is 
(under 'PHP Variables' section) and note where tempfiles are uploaded to as 
well, if you're uploading.

HTh,
Andre

--- End Message ---
--- Begin Message ---
Andre, Mirco, BDT,

  Thank you for your responses.

Here is some test code
<?php
echo "<img src=\"inline/topimage.jpg\" >";
echo "<img src=\"/inline/topimage.jpg\" >";
echo "<img src=\"" . $_SERVER['DOCUMENT_ROOT'] . "/inline/topimage.jpg\" >";
?>:

Theoretically, they should all output the same image. However:

<img src="inline/topimage.jpg" > ->IMAGE DISPLAYS
<img src="/inline/topimage.jpg" > ->IMAGE DISPLAYS
<img src="/home/sites/sitexxx/web/inline/topimage.jpg" > IMAGE DOES NOT DISPLAY

Of course, the first instance only works if the script is in the correct place 
relative to the /inline directory.

However, the second case fails if I use it in the following function (assuming I specify 
$dir as "/inline"). It returns a false result, as if it couldn't find the 
directory.

function random_img($dir,$type='random')
{
global $errors,$seed;

if (is_dir($dir)) {

$fd = opendir($dir); $images = array();

while (($part = @readdir($fd)) == true) {

         if ( eregi("(gif|jpg|png|jpeg)$",$part) ) {
             $images[] = $part;
         }
     }

   // adding this in case you want to return the image array
   if ($type == 'all') return $images;

if ($seed !== true) {
mt_srand ((double) microtime() * 1000000);
$seed = true;
}
$key = mt_rand (0,sizeof($images)-1);


   return $dir . $images[$key];

 } else {
     $errors[] = $dir.' is not a directory';
     return false;
 }
}

--
Dave Gutteridge
[EMAIL PROTECTED]/

--- End Message ---
--- Begin Message --- Dave wrote:
Here is some test code
<?php
echo "<img src=\"inline/topimage.jpg\" >";
echo "<img src=\"/inline/topimage.jpg\" >";
echo "<img src=\"" . $_SERVER['DOCUMENT_ROOT'] . "/inline/topimage.jpg\" >";
?>:


Theoretically, they should all output the same image. However:

<img src="inline/topimage.jpg" > ->IMAGE DISPLAYS
<img src="/inline/topimage.jpg" > ->IMAGE DISPLAYS
<img src="/home/sites/sitexxx/web/inline/topimage.jpg" > IMAGE DOES NOT DISPLAY

This is the expected result. $_SERVER['DOCUMENT_ROOT'] is just that. The path from root of the _filesystem_ to where Apache's document root is. This is not Apache's document root.


What you're looking for above is something like $_SERVER['HTTP_HOST'] or $_SERVER['SERVER_NAME']. I'd stick with HTTP_HOST, something like this...

echo ( "<img src=\"http://"; . $_SERVER['HTTP_HOST'] . "/path/to/image.jpg\">";

Of course, the first instance only works if the script is in the correct place relative to the /inline directory.

However, the second case fails if I use it in the following function (assuming I specify $dir as "/inline"). It returns a false result, as if it couldn't find the directory.

This is where you would want to use DOCUMET_ROOT.

--
By-Tor.com
...it's all about the Rush
http://www.by-tor.com

--- End Message ---
--- Begin Message --- Okay, for that last possibility, the one that you used the document root variable. You have to add your domain name before, the reason being is because it's relative to where the script is, if you add the domain name (http://www.whatever.org/document/root) then it switches from relative to absolute.

Dave wrote:

Andre, Mirco, BDT,

  Thank you for your responses.

Here is some test code
<?php
echo "<img src=\"inline/topimage.jpg\" >";
echo "<img src=\"/inline/topimage.jpg\" >";
echo "<img src=\"" . $_SERVER['DOCUMENT_ROOT'] . "/inline/topimage.jpg\" >";
?>:


Theoretically, they should all output the same image. However:

<img src="inline/topimage.jpg" > ->IMAGE DISPLAYS
<img src="/inline/topimage.jpg" > ->IMAGE DISPLAYS
<img src="/home/sites/sitexxx/web/inline/topimage.jpg" > IMAGE DOES NOT DISPLAY


Of course, the first instance only works if the script is in the correct place relative to the /inline directory.

However, the second case fails if I use it in the following function (assuming I specify $dir as "/inline"). It returns a false result, as if it couldn't find the directory.

function random_img($dir,$type='random')
{
global $errors,$seed;

 if (is_dir($dir)) {
 $fd = opendir($dir);  $images = array();

     while (($part = @readdir($fd)) == true) {
         if ( eregi("(gif|jpg|png|jpeg)$",$part) ) {
             $images[] = $part;
         }
     }

   // adding this in case you want to return the image array
   if ($type == 'all') return $images;

   if ($seed !== true) {
     mt_srand ((double) microtime() * 1000000);
     $seed = true;
   }
         $key = mt_rand (0,sizeof($images)-1);

   return $dir . $images[$key];

 } else {
     $errors[] = $dir.' is not a directory';
     return false;
 }
}


--- End Message ---
--- Begin Message ---
I have this simple form file:
<html>
<head>
 </head>
<body>
 <form action="test.php" method="post">
Name: <input type="text" name="name" value="your name" /><br/>
Age: <input type="text" name="age" value="your age" /><br/>
<input type="submit" name="submit" value="submit" />
</form>
</body>
</html>
Which passes (I wish!) data to this script:

<?php
$name = $_POST['name'] ;
$age = $_POST['age'] ;
print("Hello, $name! You are $age years old!");
?>

It does not work unless I turn register_globals ON  in the php.ini file. The
php
documentation leads me to believe this script SHOULD work with
register_globals
OFF.

This a NEW instasllation of the Windows IIS Server also. Is there perhaps
some
configuration on the WINDOWS SERVER that must be set for general global
data to be passed from a 'form' type page?

David F.

--- End Message ---
--- Begin Message --- David Freedman wrote:
I have this simple form file:
<html>
<head>
 </head>
<body>
 <form action="test.php" method="post">
Name: <input type="text" name="name" value="your name" /><br/>
Age: <input type="text" name="age" value="your age" /><br/>
<input type="submit" name="submit" value="submit" />
</form>
</body>
</html>
Which passes (I wish!) data to this script:

<?php
$name = $_POST['name'] ;
$age = $_POST['age'] ;
print("Hello, $name! You are $age years old!");
?>

What's the output if you put this on test.php...

<pre>
<?php

print_r ( $_POST );

?>
</pre>

--
By-Tor.com
...it's all about the Rush
http://www.by-tor.com

--- End Message ---
--- Begin Message --- What's up David... This script *should* work... I don't see any errors, but try this anyways. In your change your print command to this:

   print("Hello, " . $name . "!  You are " . $age . " years old!");

What those periods do is simply append them to each other, so in this case, you have the string, then you're appending the variable, then appending another string, then another variable, then the last string. Instead of having it all bunched up.

David Freedman wrote:

I have this simple form file:
<html>
<head>
</head>
<body>
<form action="test.php" method="post">
Name: <input type="text" name="name" value="your name" /><br/>
Age: <input type="text" name="age" value="your age" /><br/>
<input type="submit" name="submit" value="submit" />
</form>
</body>
</html>
Which passes (I wish!) data to this script:

<?php
$name = $_POST['name'] ;
$age = $_POST['age'] ;
print("Hello, $name! You are $age years old!");
?>

It does not work unless I turn register_globals ON  in the php.ini file. The
php
documentation leads me to believe this script SHOULD work with
register_globals
OFF.

This a NEW instasllation of the Windows IIS Server also. Is there perhaps
some
configuration on the WINDOWS SERVER that must be set for general global
data to be passed from a 'form' type page?

David F.




--- End Message ---
--- Begin Message --- Does anyone have any suggestions, info or references on php script/code that would enable partially completed multiple page forms that can be saved, retrieved and completed at a later date. I might add also enabling/disabling or other navigational features? I think there are are some java ones around but prefer php.

Thanks
--- End Message ---
--- Begin Message --- Are you looking to code it yourself? If so, Here's the theory behind the concept...

So you have this multiple page form that you want to save and continue at a later time correct? So you'll have to set up a save button. You will also require some way to recognize the same user when the come back (ex. a login system). So, when they half finish a form, and select the save button, you can send them to ex. save.php which will take all the user data, and store it in a mysql database, somehow tied the user (ex. a user id). When the user comes back and logs in, you can extract this form data from the database, display the form and use the form's value="" field to automatically fill in the data.

Joseph E. Maxwell wrote:

Does anyone have any suggestions, info or references on php script/code that would enable partially completed multiple page forms that can be saved, retrieved and completed at a later date. I might add also enabling/disabling or other navigational features? I think there are are some java ones around but prefer php.

Thanks


--- End Message ---

Reply via email to