php-general Digest 22 Oct 2007 23:59:49 -0000 Issue 5086

Topics (messages 263483 through 263524):

Re: Unsetting a header
        263483 by: Stut
        263484 by: Richard Heyes
        263485 by: Stut
        263486 by: Richard Heyes
        263487 by: Richard Heyes
        263488 by: Richard Heyes
        263492 by: Freyjkell
        263498 by: Richard Heyes

Different size of file on server and on output
        263489 by: Pavel Janda
        263490 by: M. Sokolewicz
        263491 by: Pavel Janda
        263493 by: Colin Guthrie

Proposal of DOM boolean property: DOMDocument::omitXMLDeclaration
        263494 by: Freyjkell
        263496 by: Rob

Proposal of DOM non-standard method: 
DOMDocument::loadCharacterEntitiesFromDtd($path)
        263495 by: Freyjkell
        263497 by: Rob

Re: Is it possible to restart Windows Apache (service) on a PHP script?
        263499 by: Peter Ford
        263519 by: Daevid Vincent
        263520 by: Daevid Vincent

running Batch process using php
        263500 by: Javed Khan
        263501 by: Ashley M. Kirchner

php suexec
        263502 by: Grant

Re: Securing PHP
        263503 by: Philip Thompson
        263504 by: Greg Donald

TLS transport for Windows
        263505 by: Matt Arnilo S. Baluyos (Mailing Lists)

problem with foreach
        263506 by: Adam Williams
        263507 by: Jason Pruim
        263508 by: Stut
        263509 by: Andrew Ballard
        263510 by: Robert Cummings
        263511 by: Adam Williams
        263512 by: Jay Blanchard
        263513 by: Robert Cummings
        263514 by: Ludovic André
        263515 by: Stut
        263516 by: Philip Thompson
        263517 by: Nathan Hawks
        263518 by: Greg Donald
        263524 by: Bastien Koert

Thoughts on multiple servers
        263521 by: Ronald Wiplinger

Php generated html email
        263522 by: Ronald Wiplinger
        263523 by: Jay Blanchard

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 ---
Richard Heyes wrote:
Maybe I'm being dense, but why not set it to what you want it to be? Clearing it is leaving the decision up to the browser which will not necessarily have the effect you want for all users.

Incidentally, it might not be possible if Apache is setting it. Not sure if PHP has the ability to override headers being sent by Apache.

The two have different effects. The Expires: header proclaims that the page is good for x hours/minutes/days etc. Whereas the browser can use the Last-Modified header to figure the staleness for itself. If its newer than the copy it has, it needs to download the newer copy.

I'm well-aware of what the headers are for, but you can construct expiry headers that match the last-modified header. As I said I'm fairly certain you will not be able in PHP to remove a header added by Apache. Given that you can't get rid of it your best option is to set it to a value that will minimise its effect.

Why can't you modify the Apache configuration to prevent it from adding this header? If not in httpd.conf then in a .htaccess file. If your host won't let you do that, switch to someone who will.

-Stut

--
http://stut.net/

--- End Message ---
--- Begin Message ---
I'm well-aware of what the headers are for, but you can construct expiry headers that match the last-modified header.

If I do that the Expiry: header will be in the past and the page will be considered expired.

--
Richard Heyes
+44 (0)800 0213 172
http://www.websupportsolutions.co.uk

Knowledge Base and HelpDesk software
that can cut the cost of online support

--- End Message ---
--- Begin Message ---
Richard Heyes wrote:
I'm well-aware of what the headers are for, but you can construct expiry headers that match the last-modified header.

If I do that the Expiry: header will be in the past and the page will be considered expired.

Sorry, I didn't articulate what I meant very well. What I meant was that you know the churn rate of your pages, so put in sensible expiry headers based on that info.

But the better way to solve it is to edit the Apache configuration to stop it putting the headers in in the first place. Why can't you do that?

-Stut

--
http://stut.net/

--- End Message ---
--- Begin Message ---
Sorry, I didn't articulate what I meant very well. What I meant was that you know the churn rate of your pages, so put in sensible expiry headers based on that info.

Unfortunately I can't foresee when the pages are changed (it won't be me who changes them).

But the better way to solve it is to edit the Apache configuration to stop it putting the headers in in the first place. Why can't you do that?

I could. I just don't know how to unset a header.


--
Richard Heyes
+44 (0)800 0213 172
http://www.websupportsolutions.co.uk

Knowledge Base and HelpDesk software
that can cut the cost of online support

--- End Message ---
--- Begin Message --- FWIW, I found what was setting the cache headers - sessions. I may be able to use session_cache_limiter(). Not Sure.

--
Richard Heyes
+44 (0)800 0213 172
http://www.websupportsolutions.co.uk

Knowledge Base and HelpDesk software
that can cut the cost of online support

--- End Message ---
--- Begin Message ---
Richard Heyes wrote:
FWIW, I found what was setting the cache headers - sessions. I may be able to use session_cache_limiter(). Not Sure.

Further, I found this to be what I needed:

session_cache_limiter('private_no_expire');

Cheers.

--
Richard Heyes
+44 (0)800 0213 172
http://www.websupportsolutions.co.uk

Knowledge Base and HelpDesk software
that can cut the cost of online support

--- End Message ---
--- Begin Message ---
D Richard Heyes wrote:
Does anyone know of a way to unset a header? I have an Expires: header that I believe Apache is setting, and I don't want it. Thanks.

Do you really need to remove this header?

--- End Message ---
--- Begin Message ---
Freyjkell wrote:
D Richard Heyes wrote:
Does anyone know of a way to unset a header? I have an Expires: header that I believe Apache is setting, and I don't want it. Thanks.

Do you really need to remove this header?

I do.

--
Richard Heyes
+44 (0)800 0213 172
http://www.websupportsolutions.co.uk

Knowledge Base and HelpDesk software
that can cut the cost of online support

--- End Message ---
--- Begin Message ---
Hello to everybody,

I have this problem with downloading files via PHP. For illustration - I am using this fragment of code:

<?php

        header("Content-type: $contenttype; name=\"$outputfilename\"");
        header("Content-disposition: form-data; filename=\"$outputfilename\"");

    $fp=fopen($filename,'r');
        while (!FEof($fp)):
                $filedata.=fread($fp,8192);
        endwhile;
        fclose($fp);
        echo $filedata;

?>

The problem is, that the file on server has 16857 bytes and saved file has 16858. In another case downloaded file has everytime 1 byte more than the original file on server.

When I put JPEG or ZIP forexample to output, there is no problem with opening file like this. Bud when I am trying .docx (Office2007 file format) it occures mistake during opening this file in MSOffice...

Can anybody helps me with this problem? Why is the file size increasing one byte? Whitch byte it is?

Thanks a lot!
Pavel

--- End Message ---
--- Begin Message ---
Pavel Janda wrote:
Hello to everybody,

I have this problem with downloading files via PHP. For illustration - I am using this fragment of code:

<?php

    header("Content-type: $contenttype; name=\"$outputfilename\"");
    header("Content-disposition: form-data; filename=\"$outputfilename\"");

    $fp=fopen($filename,'r');
    while (!FEof($fp)):
        $filedata.=fread($fp,8192);
    endwhile;
    fclose($fp);
    echo $filedata;

?>

The problem is, that the file on server has 16857 bytes and saved file has 16858. In another case downloaded file has everytime 1 byte more than the original file on server.

When I put JPEG or ZIP forexample to output, there is no problem with opening file like this. Bud when I am trying .docx (Office2007 file format) it occures mistake during opening this file in MSOffice...

Can anybody helps me with this problem? Why is the file size increasing one byte? Whitch byte it is?

Thanks a lot!
Pavel

Probably that whitespace after your last ?>
What I would recommend is to just leave off the last ?>, it's not required and by not adding it you won't see those annoying problems with whitespaces causing corrupt data.

- Tul

--- End Message ---
--- Begin Message --- Thanks a lot. However there wasn't any visible whitespace in code, leaving of ?> helped... I haven't known, that it is not required :o).

Thank you very much again!
Pavel

M. Sokolewicz napsal(a):
Pavel Janda wrote:
Hello to everybody,

I have this problem with downloading files via PHP. For illustration - I am using this fragment of code:

<?php

    header("Content-type: $contenttype; name=\"$outputfilename\"");
header("Content-disposition: form-data; filename=\"$outputfilename\"");

    $fp=fopen($filename,'r');
    while (!FEof($fp)):
        $filedata.=fread($fp,8192);
    endwhile;
    fclose($fp);
    echo $filedata;

?>

The problem is, that the file on server has 16857 bytes and saved file has 16858. In another case downloaded file has everytime 1 byte more than the original file on server.

When I put JPEG or ZIP forexample to output, there is no problem with opening file like this. Bud when I am trying .docx (Office2007 file format) it occures mistake during opening this file in MSOffice...

Can anybody helps me with this problem? Why is the file size increasing one byte? Whitch byte it is?

Thanks a lot!
Pavel

Probably that whitespace after your last ?>
What I would recommend is to just leave off the last ?>, it's not required and by not adding it you won't see those annoying problems with whitespaces causing corrupt data.

- Tul

--- End Message ---
--- Begin Message ---
M. Sokolewicz wrote:
> Pavel Janda wrote:
>> Hello to everybody,
>>
>> I have this problem with downloading files via PHP. For illustration -
>> I am using this fragment of code:
>>
>> <?php
>>
>>     header("Content-type: $contenttype; name=\"$outputfilename\"");
>>     header("Content-disposition: form-data;
>> filename=\"$outputfilename\"");
>>
>>     $fp=fopen($filename,'r');
>>     while (!FEof($fp)):
>>         $filedata.=fread($fp,8192);
>>     endwhile;
>>     fclose($fp);
>>     echo $filedata;
>>
>> ?>
>>
>> The problem is, that the file on server has 16857 bytes and saved file
>> has 16858. In another case downloaded file has everytime 1 byte more
>> than the original file on server.
>>
>> When I put JPEG or ZIP forexample to output, there is no problem with
>> opening file like this. Bud when I am trying .docx (Office2007 file
>> format) it occures mistake during opening this file in MSOffice...
>>
>> Can anybody helps me with this problem? Why is the file size
>> increasing one byte? Whitch byte it is?
>>
>> Thanks a lot!
>> Pavel
> 
> Probably that whitespace after your last ?>
> What I would recommend is to just leave off the last ?>, it's not
> required and by not adding it you won't see those annoying problems with
> whitespaces causing corrupt data.

I agree.

Also a much simpler way of outputting a file that doesn't use up memory,
is just to replace:

     $fp=fopen($filename,'r');
     while (!FEof($fp)):
         $filedata.=fread($fp,8192);
     endwhile;
     fclose($fp);
     echo $filedata;


With:
     readfile($filename);


http://uk.php.net/manual/en/function.readfile.php

Col.

--- End Message ---
--- Begin Message ---
(bool) DOMDocument::omitXMLDeclaration;

Does not need a comment. Implemented in XSLT.

// I sent this post to php.xml.dev, but I didn't get reply for long time.

--
Freyjkell

--- End Message ---
--- Begin Message ---
Freyjkell wrote:
(bool) DOMDocument::omitXMLDeclaration;

Does not need a comment. Implemented in XSLT.

// I sent this post to php.xml.dev, but I didn't get reply for long time.

parser option LIBXML_NOXMLDECL or if no DTD just save the root element.

Rob

--- End Message ---
--- Begin Message ---
DOMDocument::loadCharacterEntitiesFromDtd($path);

I like to load character entities (not whole document type definition).

When I try to do that by creating my own DTD with only character
entities, and setting resolveExternals to true, then DTD parser
complains that it didn't occur root definition.

The proposed method, if called before DOMDocument::load/loadXML(), would
get character entities from DTD (and its modules) and apply them during
parsing XML. If called multiply, or if XML contains a DTD reference,
entities put before would be overwritten.

// I sent this post to php.xml.dev, but I didn't get reply for long time.

--
Freyjkell

--- End Message ---
--- Begin Message ---
Freyjkell wrote:
DOMDocument::loadCharacterEntitiesFromDtd($path);

I like to load character entities (not whole document type definition).

When I try to do that by creating my own DTD with only character
entities, and setting resolveExternals to true, then DTD parser
complains that it didn't occur root definition.

The proposed method, if called before DOMDocument::load/loadXML(), would
get character entities from DTD (and its modules) and apply them during
parsing XML. If called multiply, or if XML contains a DTD reference,
entities put before would be overwritten.

// I sent this post to php.xml.dev, but I didn't get reply for long time.

A day or two is not a long time and some things are not cut and dry, requiring a little time to think about it. If you want to override the DTD, you should look at using catalogs or create a custom stream handler to alter the XML document as it is parsed.

Rob

--- End Message ---
--- Begin Message ---
You could try using exec to set up an "AT" job with a short delay which will
then run 'net apache restart' - I'm not a total windows guru so I can't give you
the exact recipe...

Something like exec('AT 12:00 "net apache restart"');

Check the documentation on the AT command...

One possible extra advantage is that you could cancel the 'AT' job during the
delay period if you clicked restart by accident :)

Louie Miranda wrote:
> Thanks for your suggestions.
> 
> But, both did not worked.
> 
> Louie
> 
> On 10/19/07, Philip Thompson <[EMAIL PROTECTED]> wrote:
>> On 10/19/07, Robert Degen <[EMAIL PROTECTED]> wrote:
>>> Why don't you try a
>>>
>>>   passthru('net apache restart')
>>>
>>> perhabs another parameter order, but I think It won't work.
>>> Stopping it might work, but restarting...
>>>
>>>
>>>
>>> On Fr, Okt 19, 2007 at 04:32:45 +0800, Louie Miranda wrote:
>>>> Is it possible to restart Windows Apache (service) on a PHP script?
>>>>
>>>> i have installed PHP/Apache on a Windows machine. Added the ext
>>> windows32
>>>> service.
>>>> But could not find any how to or information online.
>>>>
>>>> Please help!
>>>>
>>>> --
>>>> Louie Miranda ([EMAIL PROTECTED])
>> This reminds me of the time I was remoting into a machine (using Altiris,
>> I
>> think) to do some work on it. I then needed to restart it... so I did.
>> Well,
>> class, what happens when you turn off Mr. Computer?
>>
>> Not saying that this is the same thing...  b/c if you push a "restart"
>> command, then it *should* come back up. =/ Sorry, I don't know the exact
>> command, but consider using exec().
>>
>> Good Luck,
>> ~Philip
>>
>> PS... Yay, it's Friday!
>>
> 
> 
> 

--- End Message ---
--- Begin Message ---
What we do is setup 'sudo' to run certain commands (or a shell/ruby script
for example), then have PHP/Apache exec() the script via sudo (or use a DBUS
call to a 'root' enabled ruby daemon), which then restarts apache or
whatever we want.

Be VERY careful with the way you do this or you can give crackers all kinds
of ways to cause you pain.


For example:

[EMAIL PROTECTED]:/etc# cat /etc/sudoers
        Cmnd_Alias CHMOD = /bin/chmod
        Cmnd_Alias REBOOT = /sbin/reboot, /sbin/shutdown

        root            ALL=(ALL) ALL
        www-data        ALL=NOPASSWD: /bin/date, /sbin/hwclock,
                                REBOOT,  /usr/bin/dpkg, /usr/sbin/chpasswd,
                                /usr/bin/passwd, /usr/sbin/srvwatch,
                                /usr/sbin/srvtalk

Then in the PHP web page:

        exec("/usr/bin/sudo /sbin/reboot");


D.Vin

"Voice or no voice, the people can alway be brought to the bidding of the
leaders. This is easy. All you have to do is tell them that they are being
attacked, and denounce the pacifists for a lack of patriotism and exposing
the country to danger. It works the same in every country." --Hermann
Goering, Hitler's Reich Marshall at the Nuremberg Trials After WWII

Sound like G.W.Bush?



--- End Message ---
--- Begin Message ---
DOH!. I'm sorry I didn't read the fact that this was on Windows. My bad...

Um. Out of curiosity, why would you run LAMP as WAMP? It just seems so
wrong. Not to start an OS religion war, I use XP all day long, but I would
never use it as my dedicated web server -- that's why God invented
Unix/Linux. Best tool for the job and all that stuff...  You're just asking
for all kinds of headaches and limitations (such as the one you're
encountering now) by using the back of a screwdriver to hammer a nail
IYKWIM. You'll poke your eye out! :)

> -----Original Message-----
> From: Daevid Vincent [mailto:[EMAIL PROTECTED] 
> Sent: Monday, October 22, 2007 1:26 PM
> To: [EMAIL PROTECTED]
> Subject: RE: [PHP] Is it possible to restart Windows Apache 
> (service) on a PHP script?
> 
> What we do is setup 'sudo' to run certain commands (or a 
> shell/ruby script
> for example), then have PHP/Apache exec() the script via sudo 
> (or use a DBUS
> call to a 'root' enabled ruby daemon), which then restarts apache or
> whatever we want.
> 
> Be VERY careful with the way you do this or you can give 
> crackers all kinds
> of ways to cause you pain.
> 
> 
> For example:
> 
> [EMAIL PROTECTED]:/etc# cat /etc/sudoers
>         Cmnd_Alias CHMOD = /bin/chmod
>         Cmnd_Alias REBOOT = /sbin/reboot, /sbin/shutdown
> 
>         root            ALL=(ALL) ALL
>         www-data        ALL=NOPASSWD: /bin/date, /sbin/hwclock,
>                                 REBOOT,  /usr/bin/dpkg, 
> /usr/sbin/chpasswd,
>                                 /usr/bin/passwd, /usr/sbin/srvwatch,
>                                 /usr/sbin/srvtalk
> 
> Then in the PHP web page:
> 
>         exec("/usr/bin/sudo /sbin/reboot");
> 
> 
> D.Vin
> 
> "Voice or no voice, the people can alway be brought to the 
> bidding of the
> leaders. This is easy. All you have to do is tell them that 
> they are being
> attacked, and denounce the pacifists for a lack of patriotism 
> and exposing
> the country to danger. It works the same in every country." --Hermann
> Goering, Hitler's Reich Marshall at the Nuremberg Trials After WWII
> 
> Sound like G.W.Bush?
> 
> 
> 

--- End Message ---
--- Begin Message ---
Hello Everone,
 
I want to run a script in php which should execute at particular condition and 
if the condition is true then it will send out emails to the recipients.
Can anyone suggest how can I achieve this.
 
Thanx,
 
Javed
_________________________________________________________________
Explore the seven wonders of the world
http://search.msn.com/results.aspx?q=7+wonders+world&mkt=en-US&form=QBRE

--- End Message ---
--- Begin Message ---
Javed Khan wrote:
Hello Everone,
I want to run a script in php which should execute at particular condition and if the condition is true then it will send out emails to the recipients.
Can anyone suggest how can I achieve this.
Thanx, Javed

Without spending a whole lot of brain cells at the moment, I'd say run it through a cron task (or 'at' task if you're on a Win32 platform).


--
W | It's not a bug - it's an undocumented feature.
 +--------------------------------------------------------------------
 Ashley M. Kirchner <mailto:[EMAIL PROTECTED]>   .   303.442.6410 x130
 IT Director / SysAdmin / Websmith             .     800.441.3873 x130
 Photo Craft Imaging                       .     3550 Arapahoe Ave. #6
http://www.pcraft.com ..... . . . Boulder, CO 80303, U.S.A.
--- End Message ---
--- Begin Message ---
Hi again all,

Has anyone on this had succees setting up php to use suexec?

If I am reading things right, it appears that php must be run as CGI and 
then it will use the built in (Apache2) suexec wrapper in the same fassion 
as perl does.

If the above is correct I am looking for a primer on how to set this all up.

TIA,

-Grant 

--- End Message ---
--- Begin Message ---
On 10/20/07, Grant <[EMAIL PROTECTED]> wrote:
>
> Hi all,
>
> You've all likely heard this before...."I was hacked..." , "Had register
> globals on..." etc etc.
>
> Well, this is true of me as well.
>
> Does anyone know of a site that would help a semi professional lock down
> php, i.e.
>
> Perhaps how to install phpsuexec,
>
> Jail users to only have the ability to read/write to thier own files and
> directories,
>
> php.ini directives that have simiar affect as mentioned above.
>
> Any help appreciated.
>
> -Grant



One resource: http://phpsec.org/

~Philip

--- End Message ---
--- Begin Message ---
On 10/22/07, Philip Thompson <[EMAIL PROTECTED]> wrote:
> One resource: http://phpsec.org/

I find it very helpful to look at the actual exploits and understand
why they work:

http://www.securityfocus.com/swsearch?metaname=alldoc&query=php


-- 
Greg Donald
http://destiney.com/

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

I'm looking for a PHP environment for Windows (like XAMPP), that
already has TLS transport built-in.

Would anyone know of something like it? If not, any pointers on how to
get TLS transport for a PHP Windows environment?

Thanks,
Matt

-- 
Stand before it and there is no beginning.
Follow it and there is no end.
Stay with the ancient Tao,
Move with the present.

--- End Message ---
--- Begin Message ---
I have an html page with checkboxes:

<form action=mailform2.php method=POST>
<input type=checkbox name=option[] value="Modern Mississippi">Modern Mississippi<br>
<input type=checkbox name=option[] value="Civil Rights">Civil Rights<br>
<input type=checkbox name=option[] value="Military History">MilitaryHistory<br>
<input type=submit name=submit value=Submit>

and mailform2.php containing:

echo "you selected: <br>";
/* line 81 */ foreach ($_POST[option] as $a)
       {
       echo "$a";
       }

but I'm getting the error:

you selected:

*Warning*: Invalid argument supplied for foreach() in */var/www/sites/mdah-test/museum/mmhsurvey/mailform2.php* on line *81*

I googled some checkbox/foreach pages on google, but I don't see where I'm going wrong. I'm running php 5.2.5 on Apache 2.2.4 on Fedora Linux. Any help?
--- End Message ---
--- Begin Message ---

On Oct 22, 2007, at 1:01 PM, Adam Williams wrote:

I have an html page with checkboxes:

<form action=mailform2.php method=POST>
<input type=checkbox name=option[] value="Modern Mississippi">Modern Mississippi<br> <input type=checkbox name=option[] value="Civil Rights">Civil Rights<br> <input type=checkbox name=option[] value="Military History">MilitaryHistory<br>
<input type=submit name=submit value=Submit>

and mailform2.php containing:

echo "you selected: <br>";
/* line 81 */ foreach ($_POST[option] as $a)
       {
       echo "$a";
       }

but I'm getting the error:

you selected:

*Warning*: Invalid argument supplied for foreach() in */var/www/ sites/mdah-test/museum/mmhsurvey/mailform2.php* on line *81*

I googled some checkbox/foreach pages on google, but I don't see where I'm going wrong. I'm running php 5.2.5 on Apache 2.2.4 on Fedora Linux. Any help?

Not sure if this would help or not but when ever I've done anything with $_POST variables or other array variables I have to specify it like $_POST['option'] notice the ' in around the word 'option'

Hope it helps!


--

Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
3251 132nd ave
Holland, MI, 49424
www.raoset.com
[EMAIL PROTECTED]

--- End Message ---
--- Begin Message ---
Adam Williams wrote:
I have an html page with checkboxes:

<form action=mailform2.php method=POST>
<input type=checkbox name=option[] value="Modern Mississippi">Modern Mississippi<br>
<input type=checkbox name=option[] value="Civil Rights">Civil Rights<br>
<input type=checkbox name=option[] value="Military History">MilitaryHistory<br>
<input type=submit name=submit value=Submit>

and mailform2.php containing:

echo "you selected: <br>";
/* line 81 */ foreach ($_POST[option] as $a)
       {
       echo "$a";
       }

but I'm getting the error:

you selected:

*Warning*: Invalid argument supplied for foreach() in */var/www/sites/mdah-test/museum/mmhsurvey/mailform2.php* on line *81*

I googled some checkbox/foreach pages on google, but I don't see where I'm going wrong. I'm running php 5.2.5 on Apache 2.2.4 on Fedora Linux. Any help?

Turn notices on. You will then get lots of notices about the use of an undefined constant "option".

You should be using $_POST['option'] instead - notice the quotes.

Your HTML should really have double quotes around the attributes but that's beyond the scope of this list.

-Stut

--
http://stut.net/

--- End Message ---
--- Begin Message ---
On 10/22/07, Adam Williams <[EMAIL PROTECTED]> wrote:
> I have an html page with checkboxes:
>
> <form action=mailform2.php method=POST>
> <input type=checkbox name=option[] value="Modern Mississippi">Modern
> Mississippi<br>
> <input type=checkbox name=option[] value="Civil Rights">Civil Rights<br>
> <input type=checkbox name=option[] value="Military
> History">MilitaryHistory<br>
> <input type=submit name=submit value=Submit>
>
> and mailform2.php containing:
>
> echo "you selected: <br>";
> /* line 81 */ foreach ($_POST[option] as $a)
>         {
>         echo "$a";
>         }
>
> but I'm getting the error:
>
> you selected:
>
> *Warning*: Invalid argument supplied for foreach() in
> */var/www/sites/mdah-test/museum/mmhsurvey/mailform2.php* on line *81*
>
> I googled some checkbox/foreach pages on google, but I don't see where
> I'm going wrong.  I'm running php 5.2.5 on Apache 2.2.4 on Fedora
> Linux.  Any help?

A couple changes:

echo "you selected: <br>";

// Check to see that the value exists. If no options are checked, this
will be false.
if (array_key_exists('option', $_POST)) {
    // include the quotes as already mentioned
    foreach ($_POST['option'] as $a)
    {
        echo $a;
    }
} else {
   echo 'nothing';
}

--- End Message ---
--- Begin Message ---
On Mon, 2007-10-22 at 18:07 +0100, Stut wrote:
> Adam Williams wrote:
> > I have an html page with checkboxes:
> > 
> > <form action=mailform2.php method=POST>
> > <input type=checkbox name=option[] value="Modern Mississippi">Modern 
> > Mississippi<br>
> > <input type=checkbox name=option[] value="Civil Rights">Civil Rights<br>
> > <input type=checkbox name=option[] value="Military 
> > History">MilitaryHistory<br>
> > <input type=submit name=submit value=Submit>
> > 
> > and mailform2.php containing:
> > 
> > echo "you selected: <br>";
> > /* line 81 */ foreach ($_POST[option] as $a)
> >        {
> >        echo "$a";
> >        }
> > 
> > but I'm getting the error:
> > 
> > you selected:
> > 
> > *Warning*: Invalid argument supplied for foreach() in 
> > */var/www/sites/mdah-test/museum/mmhsurvey/mailform2.php* on line *81*
> > 
> > I googled some checkbox/foreach pages on google, but I don't see where 
> > I'm going wrong.  I'm running php 5.2.5 on Apache 2.2.4 on Fedora 
> > Linux.  Any help?
> 
> Turn notices on. You will then get lots of notices about the use of an 
> undefined constant "option".
> 
> You should be using $_POST['option'] instead - notice the quotes.
> 
> Your HTML should really have double quotes around the attributes but 
> that's beyond the scope of this list.

He's still going to get an invalid argument warning though since PHP
will automatically convert the unquoted key to a string and then look up
the value. The problem is that the value doesn't exist or is not an
array as expected.

Cheers,
Rob.
-- 
...........................................................
SwarmBuy.com - http://www.swarmbuy.com

    Leveraging the buying power of the masses!
...........................................................

--- End Message ---
--- Begin Message ---


Robert Cummings wrote:
On Mon, 2007-10-22 at 18:07 +0100, Stut wrote:
Adam Williams wrote:
I have an html page with checkboxes:

<form action=mailform2.php method=POST>
<input type=checkbox name=option[] value="Modern Mississippi">Modern Mississippi<br>
<input type=checkbox name=option[] value="Civil Rights">Civil Rights<br>
<input type=checkbox name=option[] value="Military History">MilitaryHistory<br>
<input type=submit name=submit value=Submit>

and mailform2.php containing:

echo "you selected: <br>";
/* line 81 */ foreach ($_POST[option] as $a)
       {
       echo "$a";
       }

but I'm getting the error:

you selected:

*Warning*: Invalid argument supplied for foreach() in */var/www/sites/mdah-test/museum/mmhsurvey/mailform2.php* on line *81*

I googled some checkbox/foreach pages on google, but I don't see where I'm going wrong. I'm running php 5.2.5 on Apache 2.2.4 on Fedora Linux. Any help?
Turn notices on. You will then get lots of notices about the use of an undefined constant "option".

You should be using $_POST['option'] instead - notice the quotes.

Your HTML should really have double quotes around the attributes but that's beyond the scope of this list.

He's still going to get an invalid argument warning though since PHP
will automatically convert the unquoted key to a string and then look up
the value. The problem is that the value doesn't exist or is not an
array as expected.

Cheers,
Rob.

Yeah, thats the problem I'm having for some reason.  When I do:

print_r($_POST['option']);

it prints nothing.

--- End Message ---
--- Begin Message ---
[snip]
print_r($_POST['option']);

it prints nothing.
[/snip]

Try resetting the array first, you may be at the end of the array;

reset($_POST);
print_r($_POST);

--- End Message ---
--- Begin Message ---
On Mon, 2007-10-22 at 12:20 -0500, Adam Williams wrote:
> 
> Yeah, thats the problem I'm having for some reason.  When I do:
> 
> print_r($_POST['option']);
> 
> it prints nothing.

It's usually more informative to see everything that was posted so you
might have more of an idea what may have went wrong:

    print_r( $_POST );

Cheers,
Rob.
-- 
...........................................................
SwarmBuy.com - http://www.swarmbuy.com

    Leveraging the buying power of the masses!
...........................................................

--- End Message ---
--- Begin Message ---
Adam Williams a écrit :
I have an html page with checkboxes:
[...]
but I'm getting the error:

you selected:

*Warning*: Invalid argument supplied for foreach() in */var/www/sites/mdah-test/museum/mmhsurvey/mailform2.php* on line *81*

I googled some checkbox/foreach pages on google, but I don't see where I'm going wrong. I'm running php 5.2.5 on Apache 2.2.4 on Fedora Linux. Any help?

Simple question: did you check any of the boxes before submitting? If not, then it's the reason of this error... The array does not appear in the posted variables as a not-checked checkbox is not submitted along. But all the other comments of this thread are to be taken into account as well ( $_POST['option'], trying to print_r($_POST), ...)

Ludovic André

--- End Message ---
--- Begin Message ---
Robert Cummings wrote:
On Mon, 2007-10-22 at 18:07 +0100, Stut wrote:
Adam Williams wrote:
I have an html page with checkboxes:

<form action=mailform2.php method=POST>
<input type=checkbox name=option[] value="Modern Mississippi">Modern Mississippi<br>
<input type=checkbox name=option[] value="Civil Rights">Civil Rights<br>
<input type=checkbox name=option[] value="Military History">MilitaryHistory<br>
<input type=submit name=submit value=Submit>

and mailform2.php containing:

echo "you selected: <br>";
/* line 81 */ foreach ($_POST[option] as $a)
       {
       echo "$a";
       }

but I'm getting the error:

you selected:

*Warning*: Invalid argument supplied for foreach() in */var/www/sites/mdah-test/museum/mmhsurvey/mailform2.php* on line *81*

I googled some checkbox/foreach pages on google, but I don't see where I'm going wrong. I'm running php 5.2.5 on Apache 2.2.4 on Fedora Linux. Any help?
Turn notices on. You will then get lots of notices about the use of an undefined constant "option".

You should be using $_POST['option'] instead - notice the quotes.

Your HTML should really have double quotes around the attributes but that's beyond the scope of this list.

He's still going to get an invalid argument warning though since PHP
will automatically convert the unquoted key to a string and then look up
the value. The problem is that the value doesn't exist or is not an
array as expected.

Good point. Has the OP checked any of the boxes? If not then that array will not exist in $_POST.

-Stut

--
http://stut.net/

--- End Message ---
--- Begin Message ---
On 10/22/07, Adam Williams <[EMAIL PROTECTED]> wrote:
>
> I have an html page with checkboxes:
>
> <form action=mailform2.php method=POST>
> <input type=checkbox name=option[] value="Modern Mississippi">Modern
> Mississippi<br>


Change to: <input type="checkbox" name="option[]" value="..." />...<br/>

Someone mentioned this earlier, but I thought I'd reiterate. I'm not sure
how the browser will deal with *arrays* that aren't quoted. It's very good
practice to explicitly tell what is what - don't let the browser interpret
as it wants to. (Side note: the / at the ends are for XHTML - they're
optional if only using HTML.)

~Philip

--- End Message ---
--- Begin Message ---
Also, AFAIK, PHP has always thrown a warning or notice if you use
foreach() on a non-associative array.  That doesn't mean it won't work,
but the strict standard is apparently:

foreach ($assoc as $key => $val)

not

foreach ($indexed as $item)

However, as we all know, the latter still works fine.

Despite the warning/notice you see, the code is probably still working
as expected (any other problems aside).  If you like to keep error
reporting on, you can just use an @ to suppress that error.

--- End Message ---
--- Begin Message ---
On 10/22/07, Nathan Hawks <[EMAIL PROTECTED]> wrote:
> Also, AFAIK, PHP has always thrown a warning or notice if you use
> foreach() on a non-associative array.

PHP arrays are always associative:

> cat array.php
#!/usr/bin/env php
<?php

error_reporting( E_ALL );

$a = array( 1, 2, 3 );
$b = array( 'a', 'b', 'c' );
$c = array( 1, '2', 'x' );

print_r( $a );
print_r( $b );
print_r( $c );


> ./array.php
Array
(
  [0] => 1
  [1] => 2
  [2] => 3
)
Array
(
  [0] => a
  [1] => b
  [2] => c
)
Array
(
  [0] => 1
  [1] => 2
  [2] => x
)


> That doesn't mean it won't work,
> but the strict standard is apparently:
>
> foreach ($assoc as $key => $val)
>
> not
>
> foreach ($indexed as $item)

What strict standard?  The manual shows either use being legal:

http://php.net/foreach

> However, as we all know, the latter still works fine.
>
> Despite the warning/notice you see, the code is probably still working
> as expected (any other problems aside).  If you like to keep error

What warning/notice?  What other problems?

> reporting on, you can just use an @ to suppress that error.

Errors should be handled not suppressed.


--
Greg Donald
http://destiney.com/

--- End Message ---
--- Begin Message ---
I am sure that I am late to the party, but am sure that double or single quotes 
at least are needed around the attribute values to make this work


Civil Rights


bastien





----------------------------------------> Date: Mon, 22 Oct 2007 12:20:55 
-0500> From: [EMAIL PROTECTED]> CC: [EMAIL PROTECTED]> Subject: Re: [PHP] 
problem with foreach>>>> Robert Cummings wrote:>> On Mon, 2007-10-22 at 18:07 
+0100, Stut wrote:>>>>> Adam Williams wrote:>>>>>>> I have an html page with 
checkboxes:>>>>>>>> >>>> Modern>>>> Mississippi>>>> Civil Rights>>>> 
MilitaryHistory>>>> >>>>>>>> and mailform2.php containing:>>>>>>>> echo "you 
selected: ";>>>> /* line 81 */ foreach ($_POST[option] as $a)>>>> {>>>> echo 
"$a";>>>> }>>>>>>>> but I'm getting the error:>>>>>>>> you selected:>>>>>>>> 
*Warning*: Invalid argument supplied for foreach() in>>>> 
*/var/www/sites/mdah-test/museum/mmhsurvey/mailform2.php* on line *81*>>>>>>>> 
I googled some checkbox/foreach pages on google, but I don't see where>>>> I'm 
going wrong. I'm running php 5.2.5 on Apache 2.2.4 on Fedora>>>> Linux. Any 
help?>>>>>>> Turn notices on. You will then get lots of notices about the use 
of an>>> undefined constant "option".>>>>>> You should be using 
$_POST['option'] instead - notice the quotes.>>>>>> Your HTML should really 
have double quotes around the attributes but>>> that's beyond the scope of this 
list.>>>>>>> He's still going to get an invalid argument warning though since 
PHP>> will automatically convert the unquoted key to a string and then look 
up>> the value. The problem is that the value doesn't exist or is not an>> 
array as expected.>>>> Cheers,>> Rob.>>>> Yeah, thats the problem I'm having 
for some reason. When I do:>> print_r($_POST['option']);>> it prints nothing.>> 
--> PHP General Mailing List (http://www.php.net/)> To unsubscribe, visit: 
http://www.php.net/unsub.php>

_________________________________________________________________
Are you ready for Windows Live Messenger Beta 8.5 ? Get the latest for free 
today!
http://entertainment.sympatico.msn.ca/WindowsLiveMessenger

--- End Message ---
--- Begin Message --- At current stage I have two servers installed, whereby the first one does all, but the second is a database server.

I need to install on different location a server pair, which should work together, fail-fall-over, ...

The idea is to have in the dns for the servers:

abc.example.com         <== general term
tw.abc.example.com    <== redirected to, if the user is closer to Taiwan
de.abc.example.com    <== redirected to, if the user is closer to Germany

abc will be in my office (10Mbps), tw.abc & de.abc are server co-location with each 150 Mbps.

The database server is connected to the web server via second Ethernet port and a private IP (192.168.x.x) via cross over cable. The other ethernet port of the web server is connected to the Internet (either through another ADSL, like at my office) or to like the web server directly to the Internet HUB. The mySQL servers should be set-up as a cluster server and should work together within a VPN.

Questions:
1. Any hints on above configuration?
2. Has anybody experience with a cluster mysql?
3. How to get the web servers working with the closest connection (according to the users IP) ? 4. How do I get info about the users IP (within the web server) to provide startup settings, like Time zone & so time of the user, language, country, ... ? 5. How to make it fail-fall-over if one of the server (web and/or database server!) is not working?

Thanks for you input!

bye

Ronald

--- End Message ---
--- Begin Message ---
How can I create a html email directly from a web page via Php?
The page will include tables, background colors and pictures within the tables. The received email should be readable without Internet connection (pictures, must be sent with the email)


bye

Ronald

--- End Message ---
--- Begin Message ---
[snip]
How can I create a html email directly from a web page via Php?
The page will include tables, background colors and pictures within the 
tables. The received email should be readable without Internet 
connection (pictures, must be sent with the email)
[/snip]

Google is your friend...
http://www.google.com/search?hl=en&safe=off&sa=X&oi=spell&resnum=0&ct=re
sult&cd=1&q=html+email+with+PHP&spell=1

--- End Message ---

Reply via email to