|
Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com |
php-general Digest 30 Oct 2005 03:07:53 -0000 Issue 3765
php-general-digest-help
lists.php.net
Date: Sat Oct 29 2005 - 22:07:53 CDT
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
php-general Digest 30 Oct 2005 03:07:53 -0000 Issue 3765
Topics (messages 224801 through 224836):
Images outside webroot + session = safe?
224801 by: Joseph Tura
Re: foreach / unset
224802 by: Bogdan Ribic
Re: Referencing Containing (Non-Parent) Object?
224803 by: Bogdan Ribic
Substr by words
224804 by: Danny
224818 by: Richard Lynch
224836 by: Gustavo Narea
[DONE] Substr by words
224805 by: Danny
224808 by: Minuk Choi
224810 by: tg-php.gryffyndevelopment.com
224819 by: James Benson
224820 by: Richard Lynch
Sessions and register_long_arrays
224806 by: Marcus Bointon
224807 by: Marcus Bointon
is there a number translation function?
224809 by: Linda H
224816 by: tg-php.gryffyndevelopment.com
224817 by: Greg Donald
Re: curious (and frustrating) php/apache behavior
224811 by: Don Brown
224813 by: Don Brown
224814 by: Linda H
224822 by: Petr Smith
224824 by: Richard Lynch
Retrieve Data Formated from Text field
224812 by: Danny
224815 by: Linda H
224823 by: Richard Lynch
Re: Inserting NULL Integer Values
224821 by: Richard Lynch
Re: Type of form element
224825 by: Richard Lynch
224826 by: Richard Lynch
Re: printing from php
224827 by: Richard Lynch
Re: PHP5 class constants
224828 by: Richard Lynch
Re: Using PHP for accsess control, preventing access to static files
224829 by: Richard Lynch
Re: Sending E-Mail - Setting O/S User
224830 by: Richard Lynch
Re: Detailed Report
224831 by: Richard Lynch
Re: Mixed PHP/SSI and environment variables
224832 by: Richard Lynch
224833 by: Richard Lynch
Script Multitasking
224834 by: Martin Zvarík
224835 by: Richard Lynch
Administrivia:
To subscribe to the digest, e-mail:
php-general-digest-subscribe
lists.php.net
To unsubscribe from the digest, e-mail:
php-general-digest-unsubscribe
lists.php.net
To post to the list, e-mail:
php-general
lists.php.net
----------------------------------------------------------------------
attached mail follows:
Hi there,
I am storing images outside the webroot to keep them from being accessible
for unauthorized users to see.
Then I use a script to show the images, like this:
<img src="show.php">
Now, as there is no information on the images stored in a database yet (they
have just been uploaded via ftp), I need to find a way of passing the
information as to which image is to be displayed.
I am currently trying out this way:
1. I read the filenames for all images in the upload directory into an
array.
2. I store that array in a session variable.
$_SESSION['images'] = $this->image_array;
3. I call show.php passing an array key:
<img src="show.php?id=xy">
4. In show.php I start the session, get the image information from the
session array, check if the mime type is okay and then display the image.
Of course I still need to add user authorization...
Any opinions on how safe this method seems or how it could be made
safer/more efficient? Do you think this method could be exploited to
compromise the server in any way?
Here the listing for show.php
<?php
session_start();
$file = &$_SESSION['images'][$_GET['id']];
if(is_file($file['path'].$file['file'])) {
//determine mime type and imagetype
$tmp = getimagesize($file['path'].$file['file']);
$file['mime'] = $tmp['mime'];
//if file is of valid type -> output to browser
if(in_array($file['mime'], $_SESSION['conf']['images']['allowedtypes'])) {
header("Content-Type: ".$file['mime']);
header("Content-Disposition: filename=".$file['name']);
readfile($file['path'].$file['file']);
}
}
?>
Any comments are appreciated.
jt
--
Lust, ein paar Euro nebenbei zu verdienen? Ohne Kosten, ohne Risiko!
Satte Provisionen für GMX Partner: http://www.gmx.net/de/go/partner
attached mail follows:
Richard Lynch wrote:
>
> Anyway, can you do *this* safely as a DOCUMENTED FEATURE:
>
> foreach($array as $k => $v){
> if (...) unset($array[$k]);
> }
>
Well, somewhere in the said manual it is written that foreach operates
on a *copy* of the array, so you should be safe unsetting values in the
original array while iterating through the copy.
--
Open source PHP code generator for DB operations
http://sourceforge.net/projects/bfrcg/
attached mail follows:
Morgan Doocy wrote:
> I'm trying to figure out if PHP has the facility to reference containing, non-parent objects. I have three classes, embedded hierarchically, but which are NOT extended classes of their containing objects. I'd like to be able to reference variables in the higher-level objects from the lower-level objects.
>
> To illustrate:
>
> <?php
>
> class Country {
> var $name;
> var $states;
>
> function Country($name = '', $states = array()) {
> $this->name = $name;
> $this->states = $states;
> }
> }
>
> class State {
> var $name;
> var $cities;
>
> function State($name = '', $cities = array()) {
> $this->name = $name;
> $this->cities = $cities;
> }
> }
>
> class City {
> var $name;
>
> fuction City($name = '') {
> $this->name = '';
> }
>
> function name_with_state() {
> return "$this->name, " . /* parent node reference */->name;
> }
> }
>
> $countries = array (
> 'USA' => new Country('United States',
> array (
> 'WA' => new State('Washington',
> array (
> 'SEA' => new City('Seattle'),
> 'GEG' => new City('Spokane')
> )
> ),
> 'CA' => new State('California',
> array (
> 'LAX' => new City('Los Angeles'),
> 'SFO' => new City('San Francisco')
> )
> )
> )
> )
> );
>
> echo $countries['USA']->states['WA']->cities['SEA']->name_with_state();
> // Output: 'Seattle, Washington'
>
> ?>
>
> Obviously, just extending Country doesn't make sense: a State isn't a type of Country, and a City isn't a type of State -- but States are part of Countries, and Cities are part of States. Plus, if City was just an extended State (which in turn is an extended Country), it would contain both a $states and a $cities variable. Which doesn't make sense.
>
> What, if anything, do I replace /* parent node reference */ with in City::name_with_state()?
>
> Thanks,
>
> Morgan
I suspect you want the functionality of Java embedded clases, where
embedded class can access fields of its container. If that's what you
mean, then sorry, PHP doesn't have that. You would have to keep a
reference ro parent object as a variable in child object, ie your City
should have a var $_state variable, etc.
--
Open source PHP code generator for DB operations
http://sourceforge.net/projects/bfrcg/
attached mail follows:
Hi,
I need to extract 50 words more or less from a description field. How can i
do that?. Substr, cuts the words. Is there any other way to that, without
using and array? I mean and implemented function in PHP 4.x
I´ve been googling around, but wordwrap, and substr is driving me mad...
Thanks in advance
Best Regards
--
dpc
attached mail follows:
On Sat, October 29, 2005 6:36 am, Danny wrote:
> I need to extract 50 words more or less from a description field. How
> can i
> do that?. Substr, cuts the words. Is there any other way to that,
> without
> using and array? I mean and implemented function in PHP 4.x
> I´ve been googling around, but wordwrap, and substr is driving me
> mad...
Keep in mind that the "pipe" between your database and PHP is a rather
small narrow expensive opening.
Sucking down your ENTIRE description field to throw away all but 50
characters may not be the best use of limited resources.
[This is all MOOT if you have no dreams of your site being "big" some
day.]
You therefore may want to consider something like:
select substring(description, 1, instr(description, ' ', 50)) as
description_50, substring(description, instr(description, ' ', 50), 1)
as more from ...
$description_50 will be 50 chars, more or less
$more will tell you if there was "more" or not
You will only be getting ~50 characters squeezed through that narrow
expensive db <-> PHP pipeline.
I believe that in MOST PHP/database applications this is going to be a
better performing solution, and it's somewhat "cleaner" aesthetically
than shoveling a bunch of data around that you're going to discard
anyway.
* instr may or may not be the right function in your database. I
always forget the name of this one and have to look it up.
--
Like Music?
http://l-i-e.com/artists.htm
attached mail follows:
Hello.
What do you think about this:
<?php
$MyOriginalString = "This is my original string.\nWhat do you think
about this script?";
$MaxWords = 6; // How many words are needed?
echo substr( $MyOriginalString, 0, -strlen(ereg_replace
("^([[:space:]]*[^[:space:][:cntrl:]]+){1,$MaxWords}",
"",$MyOriginalString)));
?>
Only 3 lines.
You have to change $MaxWords to 50 if that's what you need.
Best regards,
Gustavo Narea.
Danny wrote:
> Hi,
> I need to extract 50 words more or less from a description field. How can i
> do that?. Substr, cuts the words. Is there any other way to that, without
> using and array? I mean and implemented function in PHP 4.x
> I´ve been googling around, but wordwrap, and substr is driving me mad...
> Thanks in advance
> Best Regards
>
> --
> dpc
>
attached mail follows:
Finally i found it (Google is god, you only have to ask the right question)
function trim_text($text, $count){
$text = str_replace(" ", " ", $text);
$string = explode(" ", $text);
for ( $wordCounter = 0; $wordCounter <= $count;wordCounter++ ){
$trimed .= $string[$wordCounter];
if ( $wordCounter < $count ){ $trimed .= " "; }
else { $trimed .= "..."; }
}
$trimed = trim($trimed);
return $trimed;
}
Usage
------------------------------------------------
$string = "one two three four";
echo trim_text($string, 3);
---------- Forwarded message ----------
From: Danny <metalito
gmail.com>
Date: Oct 29, 2005 1:36 PM
Subject: Substr by words
To: php-general
lists.php.net
Hi,
I need to extract 50 words more or less from a description field. How can i
do that?. Substr, cuts the words. Is there any other way to that, without
using and array? I mean and implemented function in PHP 4.x
I´ve been googling around, but wordwrap, and substr is driving me mad...
Thanks in advance
Best Regards
--
dpc
--
dpc
attached mail follows:
Good job!
However, let me give a few suggestions to optimize the code
function trim_text($text, $count)
{
$text = str_replace(" ", " ", $text);
/*
* This is redundant; you are replacing all " " in $text with " "
* maybe you meant
* $text = trim($text); ?
*/
$string = explode(" ", $text);
/*
* For better programming practice, you should initialize $trimed
* I believe if you turn on error_reporting for all in php.ini
* PHP will display all warnings and errors.
*/
for ( $wordCounter = 0; $wordCounter <= $count;wordCounter++ )
/*
* Typo - you forgot the $ for wordCounter++
*
* for ( $wordCounter = 0; $wordCounter <= $count; $wordCounter++)
*/
{
$trimed .= $string[$wordCounter];
if ( $wordCounter < $count )
{
$trimed .= " ";
}
else
{
$trimed .= "...";
}
}
$trimed = trim($trimed);
return $trimed;
}
This is purely my suggestion... and I'm not saying it is better... but
if I were you, I'd do it this way :
function trim_text($text, $count)
{
$text = trim($text);
$string = explode(" ", $text);
$trimed='';
for ( $wordCounter = 0; $wordCounter <= $count; $wordCounter++ )
{
$trimed .= $string[$wordCounter].' ';
}
$trimed = trim($trimed);
if (count($string)>$count)
$trimed.='...';
return $trimed;
}
The only difference(not that you'd notice in a lightweight routine like
this) is that, I don't have that if-else block inside the loop.
Danny wrote:
>Finally i found it (Google is god, you only have to ask the right question)
> function trim_text($text, $count){
>$text = str_replace(" ", " ", $text);
>$string = explode(" ", $text);
>for ( $wordCounter = 0; $wordCounter <= $count;wordCounter++ ){
>$trimed .= $string[$wordCounter];
>if ( $wordCounter < $count ){ $trimed .= " "; }
>else { $trimed .= "..."; }
>}
>$trimed = trim($trimed);
>return $trimed;
>}
>
>Usage
>------------------------------------------------
>$string = "one two three four";
>echo trim_text($string, 3);
>
>
>---------- Forwarded message ----------
>From: Danny <metalito
gmail.com>
>Date: Oct 29, 2005 1:36 PM
>Subject: Substr by words
>To: php-general
lists.php.net
>
> Hi,
> I need to extract 50 words more or less from a description field. How can i
>do that?. Substr, cuts the words. Is there any other way to that, without
>using and array? I mean and implemented function in PHP 4.x
> I´ve been googling around, but wordwrap, and substr is driving me mad...
> Thanks in advance
>Best Regards
>
>--
>dpc
>
>
>--
>dpc
>
>
>
attached mail follows:
Good start guys. That's usually how I start down the path in solving a new problem. Invariably down the road I find a more "refined" way of doing what I did the hard way. The hard way is good though, you learn stuff along the way.
Let's see how tight we can make this though:
<?php
$string = " This is a test string of some sort. ";
$truncated = truncstr($string);
echo $truncated;
function truncstr($tmpstr) {
$maxwords = 4;
$tmpstr = trim($tmpstr);
$wordarr = explode(" ", $tmpstr);
if (count($wordarr) > $maxwords) {
$wordarr = array_slice($wordarr, 0, $maxwords);
$tmpstr = implode(" ", $wordarr) . "...";
} else {
$tmpstr = implode(" ", $wordarr);
}
return $tmpstr;
}
?>
.... Or if you want really obfuscated code...
<?PHP
$string = " This is a test string of some sort. ";
$truncated = truncstr($string);
echo $truncated;
function truncstr($tmpstr) {
return implode(" ", array_slice(explode(" ", trim($tmpstr)), 0, 4)) . "...";
}
?>
-TG
= = = Original message = = =
Good job!
However, let me give a few suggestions to optimize the code
function trim_text($text, $count)
~$text = str_replace(" ", " ", $text);
~/*
~ * This is redundant; you are replacing all " " in $text with " "
~ * maybe you meant
~ * $text = trim($text); ?
~ */
~$string = explode(" ", $text);
~
~/*
~ * For better programming practice, you should initialize $trimed
~ * I believe if you turn on error_reporting for all in php.ini
~ * PHP will display all warnings and errors.
~ */
~for ( $wordCounter = 0; $wordCounter <= $count;wordCounter++ )
~/*
~ * Typo - you forgot the $ for wordCounter++
~ *
~ * for ( $wordCounter = 0; $wordCounter <= $count; $wordCounter++)
~ */
~
~~$trimed .= $string[$wordCounter];
~~if ( $wordCounter < $count )
~~
~~~$trimed .= " ";
~~
~~else
~~
~~~$trimed .= "...";
~~
~
~$trimed = trim($trimed);
~return $trimed;
This is purely my suggestion... and I'm not saying it is better... but
if I were you, I'd do it this way :
function trim_text($text, $count)
~$text = trim($text);
~$string = explode(" ", $text);
~$trimed='';
~for ( $wordCounter = 0; $wordCounter <= $count; $wordCounter++ )
~
~~$trimed .= $string[$wordCounter].' ';
~
~$trimed = trim($trimed);
~if (count($string)>$count)
~~$trimed.='...';
~return $trimed;
The only difference(not that you'd notice in a lightweight routine like
this) is that, I don't have that if-else block inside the loop.
Danny wrote:
>Finally i found it (Google is god, you only have to ask the right question)
> function trim_text($text, $count)
>$text = str_replace(" ", " ", $text);
>$string = explode(" ", $text);
>for ( $wordCounter = 0; $wordCounter <= $count;wordCounter++ )
>$trimed .= $string[$wordCounter];
>if ( $wordCounter < $count ) $trimed .= " ";
>else $trimed .= "...";
>
>$trimed = trim($trimed);
>return $trimed;
>
>
>Usage
>------------------------------------------------
>$string = "one two three four";
>echo trim_text($string, 3);
>
>
>---------- Forwarded message ----------
>From: Danny <metalito
gmail.com>
>Date: Oct 29, 2005 1:36 PM
>Subject: Substr by words
>To: php-general
lists.php.net
>
> Hi,
> I need to extract 50 words more or less from a description field. How can i
>do that?. Substr, cuts the words. Is there any other way to that, without
>using and array? I mean and implemented function in PHP 4.x
> I~ve been googling around, but wordwrap, and substr is driving me mad...
> Thanks in advance
>Best Regards
>
>--
>dpc
>
>
>--
>dpc
___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.
attached mail follows:
Did you actually test that?
Even better version of your function,
<code>
$string = "one two three four";
echo substr($string, -4);
echo '...';
</code>
James
Danny wrote:
> Finally i found it (Google is god, you only have to ask the right question)
> function trim_text($text, $count){
> $text = str_replace(" ", " ", $text);
> $string = explode(" ", $text);
> for ( $wordCounter = 0; $wordCounter <= $count;wordCounter++ ){
> $trimed .= $string[$wordCounter];
> if ( $wordCounter < $count ){ $trimed .= " "; }
> else { $trimed .= "..."; }
> }
> $trimed = trim($trimed);
> return $trimed;
> }
>
> Usage
> ------------------------------------------------
> $string = "one two three four";
> echo trim_text($string, 3);
>
>
> ---------- Forwarded message ----------
> From: Danny <metalito
gmail.com>
> Date: Oct 29, 2005 1:36 PM
> Subject: Substr by words
> To: php-general
lists.php.net
>
> Hi,
> I need to extract 50 words more or less from a description field. How can i
> do that?. Substr, cuts the words. Is there any other way to that, without
> using and array? I mean and implemented function in PHP 4.x
> I´ve been googling around, but wordwrap, and substr is driving me mad...
> Thanks in advance
> Best Regards
>
> --
> dpc
>
>
> --
> dpc
>
attached mail follows:
On Sat, October 29, 2005 10:51 am, Minuk Choi wrote:
> function trim_text($text, $count)
> {
> $text = str_replace(" ", " ", $text);
> /*
> * This is redundant; you are replacing all " " in $text with " "
> * maybe you meant
> * $text = trim($text); ?
> */
It was probably replacing *TWO* spaces with one.
If so, it should really be in a while loop, because there could be 3
or more spaces in a row, and if the goal is only single-spaced
words...
//Replace 2 spaces with 1 until all words are single-spaced
while (strstr($text, ' ')) $text = str_replace(' ', ' ', $text);
PS
My post was doing 50 LETTERS, not 50 words.
So change 50 to 250 and call it done. :-)
Unless the word-count is really that critical...
--
Like Music?
http://l-i-e.com/artists.htm
attached mail follows:
Strange behaviour that's taken me ages to track down. I have the
situation where I can create a session, but any changes to it are not
saved. session_write_close() didn't help. Eventually I tracked it
down: if you have register_long_arrays disabled (as is the default in
PHP5), this can happen. Enabling it fixed the problem. A very simple
test case didn't show this problem, so I guess something in my
sessions has a dependency on HTTP_GET_VARS or similar, though these
old-style vars do not appear anywhere in my code... Some of the
libraries I'm using may use them (for example Smarty, though I have
the request_use_auto_globals option enabled for that which should
stop it using them), but nothing to do with them is stored in the
session. If I look at a session file, it's all just scalars and
arrays, no complex types at all, but changing an item in $_SESSION
simply does not get saved back to the session file if
register_long_arrays is enabled.
Anyone else seen this? Any idea why it might be happening?
Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
marcus
synchromedia.co.uk | http://www.synchromedia.co.uk
attached mail follows:
On 29 Oct 2005, at 14:48, Marcus Bointon wrote:
> changing an item in $_SESSION simply does not get saved back to the
> session file if register_long_arrays is enabled.
I meant disabled.
I've also tried using it with the mm session save handler and I get
the same symptoms. I also get identical results on OS X and Linux.
FYI, I want to disable this setting for increased performance,
especially as I'm not using these old arrays anyway.
Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
marcus
synchromedia.co.uk | http://www.synchromedia.co.uk
attached mail follows:
Hi,
Does anyone know of a function for translating a decimal number into an
English number. In other words, if you pass it 1 it will return 'one', if
you pass it 127 it will return 'one hundred twenty seven', and etc.
Thanks,
Linda
attached mail follows:
I couldn't find one out there Linda (and I'm sure I've seen them before) so since I'm stuck at work on a Saturday I thought I'd take a break and see if I could hack this out myself.
Probably a more elegant way to do this, but here's what I came up with. Feel free to use and modify it at will.
It should be infinitely expandable by adding to the "$places" array. (well, 'infinite' in regards to your system's ability to handle long strings, no long ints or floats are used so that shouldn't limit it).
Let me know if you have any questions or if anyone can improve this (always up for learning new tricks :)
Good luck Linda!
-TG
<?PHP
$numerals = array(1 => "one",
2 => "two",
3 => "three",
4 => "four",
5 => "five",
6 => "six",
7 => "seven",
8 => "eight",
9 => "nine",
10 => "ten",
11 => "eleven",
12 => "twelve",
13 => "thirteen",
14 => "fourteen",
15 => "fifteen",
16 => "sixteen",
17 => "seventeen",
18 => "eighteen",
19 => "nineteen",
20 => "twenty",
30 => "thirty",
40 => "fourty",
50 => "fifty",
60 => "sixty",
70 => "seventy",
80 => "eighty",
90 => "ninety"
);
$places = array(1 => "hundred",
2 => "thousand",
3 => "million",
4 => "billion",
5 => "trillion",
6 => "quadrillion"
);
$testnumber = "1,205,513";
$number = str_replace(",", "", trim($testnumber));
$rev_number = strrev($number);
$rev_numberarr = explode("|||", wordwrap($rev_number, 3, "|||", 1));
$x = 1;
$outarr = array();
foreach ($rev_numberarr as $order => $rev_num_block) {
$tmpoutput = "";
$num_block = sprintf("%03s", strrev($rev_num_block));
list($pos_one, $pos_two, $pos_three) = explode("|||", wordwrap($num_block, 1, "|||", 1));
if (intval($pos_one) <> 0) $tmpoutput = $numerals[$pos_one] . " hundred " . $tmpoutput . " ";
if (intval($pos_two . $pos_three) <= 20 OR (intval($pos_two) <> 0 AND intval($pos_three) == 0)) {
$tmpoutput .= $numerals[intval($pos_two . $pos_three)];
} elseif (intval($pos_two) == 0) {
$tmpoutput .= $numerals[$pos_three] . $tmpoutput;
} elseif (intval($pos_two) <> 0 AND intval($pos_three) <> 0) {
$tmpoutput .= $numerals[$pos_two . $pos_three] . $tmpoutput;
}
if ($x > 1) $tmpoutput .= " " . $places[$x];
array_unshift($outarr, $tmpoutput);
//$output = $tmpoutput . " " . $output; # Can just use this instead of "array_unshift" if you don't need to put comma dividers
$x++;
}
$output = implode(", ", $outarr); // If you don't use an array, remove this line too
echo $testnumber . "<br>\n";
echo "becomes<br>\n";
echo "\"" . ucwords($output) . "\"";
?>
= = = Original message = = =
Hi,
Does anyone know of a function for translating a decimal number into an
English number. In other words, if you pass it 1 it will return 'one', if
you pass it 127 it will return 'one hundred twenty seven', and etc.
Thanks,
Linda
___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.
attached mail follows:
On Sat, 2005-10-29 at 12:13 -0700, Linda H wrote:
> Does anyone know of a function for translating a decimal number into an
> English number. In other words, if you pass it 1 it will return 'one', if
> you pass it 127 it will return 'one hundred twenty seven', and etc.
http://pear.php.net/package-info.php?package=Numbers_Words
--
Greg Donald
Zend Certified Engineer
MySQL Core Certification
http://destiney.com/
attached mail follows:
We're having a problem getting more than one imbedded PHP script to execute
in our Apache-served pages. We're using Apache 2.0.40 server-side includes.
We wish to include multiple PHP scripts into our pages but are only
succeeding in having the first included PHP script executed; the rest are
ignored or misinterpreted as HTML...
Thank you in advance for any help you provide.
This works:
$ cat php1.txt
<?php
echo "this is the first php include";
?>
$ cat test.shtml
<html><body>
<!--#INCLUDE virtual="/php1.txt"-->
<br>this came from html
</body></html>
Producing the expected result from the browser (http://myhost/test.shtml):
this is the first php include
this is html
However, this does not produce the expected three line result:
$ cat php1.txt
<?php
echo "this is the first php include";
?>
$ cat php2.txt
<?php
echo "this is the second php include";
?>
$ cat test.shtml
<html><body>
<!--#INCLUDE virtual="/php1.txt"-->
<br>
this came from html
<br>
<!--#INCLUDE virtual="/php2.txt"-->
</body></html>
Producing from the browser (http://myhost/test.shtml):
this is the first php include
this is html
This DOES work:
$cat test.php
<html><body>
<?php
echo "this is from the first php block";
?>
<br>
this is from html
<br>
<?php
echo "this is from the second php block";
?>
</body></html>
Producing from the browser (http://myhost/test.php):
this is from the first php block
this is from html
this is from the second php block
Don Brown
Co-Founder, Utah Skies
"Ski champagne powder by day, surf diamond-studded velvet by night..."
attached mail follows:
We're having a problem getting more than one imbedded PHP script to execute in our Apache-served pages. We're using Apache 2.0.40 server-side includes. We wish to include multiple PHP scripts into our pages but are only succeeding in having the first included PHP script executed; the rest are ignored or misinterpreted as HTML...
Thank you in advance for any help you provide.
This works:
$ cat php1.txt
<?php
echo "this is the first php include";
?>
$ cat test.shtml
<html><body>
<!--#INCLUDE virtual="/php1.txt"-->
<br>this came from html
</body></html>
Producing the expected result from the browser (http://myhost/test.shtml):
this is the first php include
this is html
However, this does not produce the expected three line result:
$ cat php1.txt
<?php
echo "this is the first php include";
?>
$ cat php2.txt
<?php
echo "this is the second php include";
?>
$ cat test.shtml
<html><body>
<!--#INCLUDE virtual="/php1.txt"-->
<br>
this came from html
<br>
<!--#INCLUDE virtual="/php2.txt"-->
</body></html>
Producing from the browser (http://myhost/test.shtml):
this is the first php include
this is html
This DOES work:
$cat test.php
<html><body>
<?php
echo "this is from the first php block";
?>
<br>
this is from html
<br>
<?php
echo "this is from the second php block";
?>
</body></html>
Producing from the browser (http://myhost/test.shtml):
this is from the first php block
this is from html
this is from the second php block
Don Brown
Co-Founder, Utah Skies
"Ski champagne powder by day, surf diamond-studded velvet by night..."
attached mail follows:
>We wish to include multiple PHP scripts into our pages but are only
>succeeding in having the first included PHP script executed; the rest are
>ignored or misinterpreted as HTML...
I don't know if this is part of your problem, but when you do an include,
it throws you out of php. So, if there is any php code in the include, you
can't rely on the include being inside a php block. You must put a php
block inside the include as well. This is true no matter how you name the
include file (.php, .inc, .htm).
Linda H
attached mail follows:
Hi,
why don't you use normal php include (require) functions? Why do you
want to mix apache server side includes with php code? There is nothing
php include can't do..
Just change all
<!--#INCLUDE virtual="xxxx"-->
to
<? include('xxxx'); ?>
Petr
Don Brown wrote:
> We're having a problem getting more than one imbedded PHP script to execute in our Apache-served pages. We're using Apache 2.0.40 server-side includes. We wish to include multiple PHP scripts into our pages but are only succeeding in having the first included PHP script executed; the rest are ignored or misinterpreted as HTML...
>
> Thank you in advance for any help you provide.
>
>
> This works:
>
> $ cat php1.txt
> <?php
> echo "this is the first php include";
> ?>
> $ cat test.shtml
> <html><body>
>
> <!--#INCLUDE virtual="/php1.txt"-->
>
> <br>this came from html
>
> </body></html>
>
> Producing the expected result from the browser (http://myhost/test.shtml):
> this is the first php include
> this is html
>
> However, this does not produce the expected three line result:
>
> $ cat php1.txt
> <?php
> echo "this is the first php include";
> ?>
> $ cat php2.txt
> <?php
> echo "this is the second php include";
> ?>
> $ cat test.shtml
> <html><body>
>
> <!--#INCLUDE virtual="/php1.txt"-->
> <br>
> this came from html
> <br>
> <!--#INCLUDE virtual="/php2.txt"-->
>
> </body></html>
>
> Producing from the browser (http://myhost/test.shtml):
> this is the first php include
> this is html
>
>
> This DOES work:
>
> $cat test.php
> <html><body>
>
> <?php
> echo "this is from the first php block";
> ?>
>
> <br>
> this is from html
> <br>
>
> <?php
> echo "this is from the second php block";
> ?>
>
> </body></html>
>
> Producing from the browser (http://myhost/test.shtml):
> this is from the first php block
> this is from html
> this is from the second php block
>
>
> Don Brown
> Co-Founder, Utah Skies
> "Ski champagne powder by day, surf diamond-studded velvet by night..."
>
attached mail follows:
On Sat, October 29, 2005 12:01 pm, Don Brown wrote:
> We're having a problem getting more than one imbedded PHP script to
> execute in our Apache-served pages. We're using Apache 2.0.40
> server-side includes. We wish to include multiple PHP scripts into our
> pages but are only succeeding in having the first included PHP script
> executed; the rest are ignored or misinterpreted as HTML...
>
> Thank you in advance for any help you provide.
>
>
> This works:
>
> $ cat php1.txt
> <?php
> echo "this is the first php include";
> ?>
> $ cat test.shtml
> <html><body>
>
> <!--#INCLUDE virtual="/php1.txt"-->
You are using Server Side Include (SSI) here.
SSI is to PHP as a GoCart is to a Ferrarri :-)
*IF* your original page of HTML can be parsed as PHP, you'll have a
lot less frustration and a lot more flexibility using:
<?php include 'php1.txt'?>
instead.
But let's assume that you are:
A) Stuck with the HTML being HTML.
B) Don't need variables/data from php1.txt to transfer to php2.txt
later in the script
C) Are willing to accept the increased HTTP performance hit of <!--
#INCLUDE virtual...> which, I *THINK* will chew up another HTTP
connection
If you're okay with all of that, you probably just need to change
php1.txt to php1.php so that when it is requested, Apache "knows" that
it is PHP code, and not plain text.
*.txt -> Apache mime-type makes Apache think it's plain/text
*.php -> Apache mime-type makes Apache think it's PHP
These are just the defaults.
You can configure Apache with ForceType (and friends) to make all your
.txt files pass through PHP, or all your .htm or .html files pass
through PHP.
Whether you really WANT to pass *ALL* .txt files through PHP is pretty
questionable.
All .htm and .html files through PHP is quite common and has many
benefits.
PS I got no idea how you managed to get the FIRST php block to work
and not the second... Unless one of them has .php as part of the
filename
--
Like Music?
http://l-i-e.com/artists.htm
attached mail follows:
Hi Gurus,
I´ve got a problem with the result displaying a "TEXT" type field
The data is inserted into db in this way:
"Hello,
This is a sample of first line.
This is another paragraph, blah
blah blah
Bye"
But the result is in one paragraph:
"Hello, This is a sample of first line.
This is another paragraph, blah
blah blah Bye"
If I use HTML <PRE> label, I´ve got the result correct, but cannot use
styles
Any Suggestion?
thx .
--
dpc
attached mail follows:
> The data is inserted into db in this way:
> "Hello,
> This is a sample of first line.
> This is another paragraph, blah
>blah blah
>Bye"
> But the result is in one paragraph:
> "Hello, This is a sample of first line.
>This is another paragraph, blah
>blah blah Bye"
It sounds as if your database record includes a carriage return or new line
character (\n), which is not recognized in html (except using the <pre> tag.
You need to replace the new line with an html <p> tag. You might want to
store each paragraph in a different database record (make a table for the
text. It will include a key that connects it to the main record, the text,
and a sequence number that tells you the order in which the paragraphs
should be displayed).
Linda H
attached mail follows:
http://php.net/nl2br
On Sat, October 29, 2005 12:07 pm, Danny wrote:
> Hi Gurus,
> I´ve got a problem with the result displaying a "TEXT" type field
> The data is inserted into db in this way:
> "Hello,
> This is a sample of first line.
> This is another paragraph, blah
> blah blah
> Bye"
> But the result is in one paragraph:
> "Hello, This is a sample of first line.
> This is another paragraph, blah
> blah blah Bye"
> If I use HTML <PRE> label, I´ve got the result correct, but cannot
> use
> styles
> Any Suggestion?
> thx .
>
> --
> dpc
>
--
Like Music?
http://l-i-e.com/artists.htm
attached mail follows:
On Sat, October 29, 2005 4:45 am, Bogdan Ribic wrote:
>> $value1 = 'xyz","xyz"); DELETE FROM MYTABLE;';
>>
>> you might get surprising results!
>>
>> This is called SQL injection and it's important to escape all the
>> values
>> before putting them into the statement.
>
>
> Did you try that? This doesn't work on my machine:
>
> mysql_query("DELETE FROM mytable; DELETE FROM mytable;");
>
> ie, mysql extension won't let me do more than one statement at a time.
PHP MySQL has not allowed multiple statements per query for awhile, I
think.
I also think it's possible to change that, or that it might change in
the future.
Regardless of all that, the general principle remains sound.
Even if the one specific example does not work, that doesn't mean that
there aren't a few billion that WILL work to compromise your site.
http://phpsec.org
--
Like Music?
http://l-i-e.com/artists.htm
attached mail follows:
On Fri, October 28, 2005 10:00 am, Shaun wrote:
> I have some checkboxes on my page which correspond with boolean fields
> in my
> database - actually they are TINYINT's in which I store a 0 or 1 in
> for
> false and true values respectively.
>
> Is it possible to loop through all $_POST values to see if it is a
> checkbox?
> If so then for that element if it is equal to 'on' then change it to 1
> otherwise change it to 0?
No.
The only things you get in POST are:
name (string)
value (string)
PHP does provide the feature (some call it mis-feature) of array
processing on name, so that:
name[index] turns into $name['index']
If you want to identify your checkboxes as checkboxes, you will need
some external, application-specific way to do so.
You could:
#1. Use Hungarian Notation (ugh!) in your checkbox field names, so you
would know that any 'name' that starts with 'ckbx' was a checkbox.
#2. Have an array of known checkbox fields in your PHP
<?php
$checkboxes = array('spam_me', 'read_terms', 'whatever');
?>
And then you could compare each $_POST index with that array.
Improving performance using $checkboxes with KEYS of the names instead
of values is left as an exercise for the reader :-)
You also need to be aware that HTTP does *NOT* transmit "off" checkboxes.
If the user has 3 checkboxes, and selects only 1, you get *NOTHING* in
$_POST about the other 2 checkboxes.
The very lack of any POST data tells you the checkboxes are "off"
So you will most likely be using isset($_POST['checkbox_name']) rather
than testing for "on"
--
Like Music?
http://l-i-e.com/artists.htm
attached mail follows:
> I usually place a hidden field with the same name as the checkbox
> field before the actual checkbox field. I store my 'false' value in
> there. If the checkbox is checked the hidden field is overridden.
>
> <?php
>
> error_reporting( E_ALL );
>
> if( isset( $_POST[ 'submit' ] ) )
> {
> echo '<pre>';
> print_r( $_POST );
> echo '</pre>';
> }
>
> echo <<<EOF
> <form method='post' action='$_SERVER[PHP_SELF]'>
> <input type='hidden' value='0' name='blah'>
> <input type='checkbox' value='1' name='blah'> Blah?
> <input type='submit' name='submit'>
> </form>
> EOF;
>
> ?>
This probably works just fine in all browsers, but...
I don't THINK the HTML and HTTP specification specificially require
ordering of HTML/INPUT/POST elements to "match up"
In fact, as I recall (and it's been YEARS since I read the damn thing)
I believe they specifically said that the ordering was NOT to be
relied upon...
Though this may well have changed in HTTP/HTML 3.0, 4.0, XHTML, etc
vesions of specifications.
It also seems like rather needless bloat of HTML, to me, unless I'm
missing something.
$blah = isset($_POST['blah']);
//update or process $blah
If the processing of $blah is particularly expensive or heinous, and
it's a pre-existing preference type of setting, I can see the savings,
but given the overhead of checking every value going in/out to compare
before update, it seems like the overhead outweighs the savings, and
clutters up the code...
--
Like Music?
http://l-i-e.com/artists.htm
attached mail follows:
On Fri, October 28, 2005 6:17 am, Tom Cruickshank wrote:
> I've been reading up on printing out documents using PHP (using
> Printer
> functions calls in the php manual)
>
> I'm using a Linux and/or FreeBSD operating system to run my php code
> on (in
> apache). However, I am surfing these pages using a Windows XP machine.
>
> Has anyone ever tried having a print button (or link) in php that
> would make
> Whatever page is being displayed being printed with the above
> scenario?
>
> How might you of gone about it to make it work? (the Linux or FreeBSD
> box is
> not configured to have a printer on it, shared or local, does that
> make a
> difference? )
If you are trying to get the print-out on a printer tied to the
server, PHP is maybe going to be involved.
If you want it printed to a printer tied to the client (browser) PHP
is long-gone and has nothing to do with it by the time you click on
"Print" button.
There are a bunch of JavaScript "print" buttons/links/scripts you can
find with Google to help.
If you need your HTML to be made printer-friendly BEFORE you print it,
PHP and http://php.net/pdflib may help. Or is it
http://php.net/libpdf? I can never remember.
--
Like Music?
http://l-i-e.com/artists.htm
attached mail follows:
On Thu, October 27, 2005 9:56 pm, Chris wrote:
> Though I suppose you could make an argument for using expressions that
> consist of only constant values.
Actually...
One could argue that so long as the programmer was willing to accept
the consequences, there could be many legitimate circumstances in
which one might WANT to utilize non-constant values for a const.
Off the top of my head, there are:
1. A 'random' value which should be set for the course of the run/script
2. An environment 'variable' which comes from some external source.
3. A time() [and friends] value for profiling
4. Time computations such as (60*60*24).
[Re #4] Not all Programmers have memorized and immediately recognize
the value that 60*60*24 works out to, but they'd be hard pressed to
not recognize those numbers as seconds/minutes/hours...
In some languages, it is possible to use a pre-processor construct to
have the interpreter/compiler compute a value in its first-pass, and
to store that value as a constant in the program for actual execution.
#. was what I recall from Lisp, about a decade ago. It was quite
useful in many cases.
I'm pretty sure C's macros and pre-processor macros and all that junk
that gave me headaches was (partially) meant to accomplish the same
thing. :-)
I'm not sure PHP *needs* this feature, but I can certainly see that it
would be useful to a lot more programmers than some stuff that is
being worked on for PHP5+. :-) :-) :-)
--
Like Music?
http://l-i-e.com/artists.htm
attached mail follows:
On Thu, October 27, 2005 11:05 am, Dan Trainor wrote:
> It's been suggested to use readfile() to accomplish this, by
> forwarding
> content from outside of the document root - but this just sounds odd.
> On top of being (what I think would be) incredibly slow, it just
> doesn't
> sound "right".
A) It's right.
B) readfile is the same thing in PHP that Apache would do in Apache,
basically:
PHP::readfile == Apache::readfile
So your overhead is a few function calls to the PHP Module, a load-up
of your "download.php" script from the hard drive, and then a few
function calls in PHP.
Now, out of all that, the only thing "expensive" is download.php
coming off the disk drive.
If you have a PHP Cache of some kind (Zend Cache, et al) then this is
cheap.
If your OS/disk has a Cache, then this is cheap.
If your server gets slammed and "download.php" isn't in RAM, then it
gets expensive.
Only stress tests on your server will tell you how expensive it will
be, but its' not like the script will take you long to write:
<?php
session_start();
if (!$_SESSION['authenticated'])) header("Location:
http://example.com/login.php");
$filename = $_GET['filename'];
//scrub $filename better than this, but it's a start:
$filename = basename($filename);
readfile("/full/path/to/non/web/storage/area/of/downloads/only/$filenaem");
?>
That's pretty much it.
Change it, test it, stress it, and see if PHP/readfile really slows
you down compared to a direct download with no access control at all.
I'm betting the answer is "No"
If PHP is too slow, you've still got two good benchmarks to compare
other solutions against, and it only took you, what?, a couple hours
to develop them?
--
Like Music?
http://l-i-e.com/artists.htm
attached mail follows:
On Thu, October 27, 2005 5:04 am, Cabbar Duzayak wrote:
> When someone sends an e-mail using php, exim sets the following 2
> headers (along with others of course):
>
> Received: from x.x.x.x (EHLO host.mydomain.com) (x.x.x.x) by
> mta151.mail.dcn.yahoo.com with SMTP; Wed, 24 Sep 2005 10:29:04 -0700
>
> Received: from <O/S User> by host.mydomain.com with local (Exim 4.52)
> id 3ABiAO-00019o-KL for yahoouser
yahoo.com; Thu, 27 Oct 2005 13:29:03
> +0300
>
> Here, the <O/S User> is picked up from the operation system, and it is
> the user that owns the process, which is the process that initiates
> sending out this e-mail.
>
> Is there a way to specify a certain user instead of the owner of the
> current process, or is there a way to configure exim such that, it
> won't pick up the owner of that process for this header, but a
> specific user that I explicitly specify through configuration?
Maybe.
In php.ini, you set the sendmail_path.
Your sendmail_path presumably uses exim instead of sendmail?
At any rate, if there are command line args for exim to set the "From"
or whatever it is you want changed, you can cram them into the
sendmail_path in php.ini, and that changes what happens when mail is
sent.
If your mail agent does NOT support those as command line args, you
could perhaps set up a special configuration of exim for PHP to run
that has the right /etc/exim.conf (or whatever) files to make it do
what you want.
I really only half-understand this with sendmail, and I know zilch
about exim, but at least this MIGHT work for you.
--
Like Music?
http://l-i-e.com/artists.htm
attached mail follows:
On Thu, October 27, 2005 4:26 am, Danny wrote:
> I´ve got a connection, to a MySQL db, and get the following
> ResultSet(Category | Name | Code | City)
> Customers | John | A36 | New York
> Customers | Jason | B45 | Los Angeles
> Customers | Max | A36 | Paris
> Providers | John | A36 | London
> Providers | Mark | B67 | Madrid
You must make sure that your query has:
ORDER BY Category
in it, and any other ordering (Name, Code, City) comes *AFTER* Category.
Otherwise, your Customers and Providers get all jumbled up, and you
can't easily separate them.
> And I need the report in the following format:
$last_category = '';
while (list($category, $name, $code, $city) = mysql_fetch_row($result)){
//Only print out Category when we find a new one:
if ($last_category != $category){
echo " $category<br />\n";
$last_category = $category;
}
echo "$name - $code - $city<br />\n";
}
--
Like Music?
http://l-i-e.com/artists.htm
attached mail follows:
On Thu, October 27, 2005 3:43 am, Christoph Freundl wrote:
> I have a problem with the persistence of environment variables when
> mixing PHP and SSI (Apache) and I am not sure if I just made an error
> or if this approach cannot work at all.
> So please consider the following files:
I *believe* that there are two different scenarios here:
1. Each "virtual" is a totally separate HTTP request, in the
"stateless" HTTP protocol, and your environment variables in one will
not (ever) survive to the next.
2. Apache is configured to do "virtual" requests as some kind of
"sub-request" and it's all in one single HTTP request/process/thread.
I *think* this is a feature I've read about in HTTP specification at
http://apache.org
If I'm right about all this, none of this has much to do with PHP
really, and has everything to do with Apache and configuration. You'd
have the same issues in mod_perl or mod_python as you are having in
PHP.
PS Abondon SSI and just use PHP and your headaches will all disappear.
:-)
--
Like Music?
http://l-i-e.com/artists.htm
attached mail follows:
On Fri, October 28, 2005 9:36 am, Christoph Freundl wrote:
> Perhaps I return to what I primarily intended to ask: is it really the
> wanted behaviour of virtual() that changes that are made by the
> included file do not influence the environment of the including file?
That is most definitely a desirable behaviour for some users.
/virtual is a separate HTTP requestm just as if the user had surfed
there and crammed in the result.
HTTP is stateless for various reasons.
There are pros and cons to that, but it was not done on a whim.
You MIGHT be able to pass myvar *into* the /virtual as a GET arg...
<!-- #virtual /whatever.shtml?myvar=<!-- #print myvar -->-->
I'm pretty sure of 2 things:
1. <!-- #print myvar --> is probably not how you print out an SSI var.
2. Even if it *IS* how you do it, nesting the <!-- # directives ain't
gonna work.
But you get the idea.
--
Like Music?
http://l-i-e.com/artists.htm
attached mail follows:
Hi,
I have a file, which I run using command line. The file I am running,
runs several files using passthru().
What I realise is, that it runs each file in sequence and waits for its
result.
I need to run all files at once and they don't have to return the result
to the main file. How do I do this?
Any help appreciated!
Martin Zvarik
attached mail follows:
On Sat, October 29, 2005 3:57 pm, Martin Zvarík wrote:
> I have a file, which I run using command line. The file I am running,
> runs several files using passthru().
> What I realise is, that it runs each file in sequence and waits for
> its
> result.
> I need to run all files at once and they don't have to return the
> result
> to the main file. How do I do this?
Couple Options:
Change your script to accept a single filename from the command line
($argv) and then run several of that script from command line in the
background:
php -q singlefileprocess.php datafile1.txt &
php -q singlefileprocess.php datafile2.txt &
php -q singlefileprocess.php datafile3.txt &
http://php.net/pcntl
This basically would be the same (sort of) as just running multiple
copies of your PHP script, one for each file, but keeps your script
able to process multiple files...
Not sure it's worth the effort, but there it is.
You could also use http://php.net/exec to have PHP fire up more PHP
scripts in the background:
<?php
//loop through $filename
exec("/full/path/to/php -q processonefile.php $filename &", $output,
$error);
if ($error) echo "OS Error: $error\n";
echo implode("", $output);
if ($error) exit;
?>
Note that in all cases, not only with the results most likely not
return to the main file, they'll be reading the files in parallel and
doing whatever to them... Be sure that this won't affect other parts
of the application.
--
Like Music?
http://l-i-e.com/artists.htm
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]