php-general Digest 15 Mar 2013 19:32:31 -0000 Issue 8164

Topics (messages 320557 through 320585):

Re: variable type - conversion/checking
        320557 by: Peter Ford
        320559 by: tamouse mailing lists

Type of a variable in PHP
        320558 by: Kevin Peterson
        320560 by: Karim Geiger
        320563 by: Lester Caine
        320565 by: Sebastian Krebs

rather a HTML Q; however 2-FRAME
        320561 by: georg
        320564 by: tamouse mailing lists
        320567 by: Tim Streater
        320575 by: georg
        320576 by: georg
        320577 by: Stuart Dallas
        320578 by: georg
        320581 by: tamouse mailing lists
        320582 by: Jim Giner

Re: PHP context editor
        320562 by: Karim Geiger
        320566 by: Sebastian Krebs

Undefined index....
        320568 by: Jay Blanchard
        320570 by: Serge Fonville
        320571 by: Jay Blanchard
        320572 by: Serge Fonville
        320573 by: Lester Caine
        320579 by: Tim Streater
        320580 by: Jay Blanchard

Re: Accessing Files Outside the Web Root
        320569 by: Dale H. Cook
        320574 by: Stuart Dallas
        320583 by: Dale H. Cook
        320584 by: Marc Guay

PDO Transaction
        320585 by: Simon Dániel

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
On 15/03/13 06:21, Jim Lucas wrote:
On 3/14/2013 4:05 PM, Matijn Woudt wrote:
On Thu, Mar 14, 2013 at 11:44 PM, Jim Lucas <li...@cmsws.com> wrote:

On 03/14/2013 11:50 AM, Samuel Lopes Grigolato wrote:

Something like "if (is_numeric($var)&& $var == floor($var))" will do
the

trick. I don't know if there's a better (more elegant) way.


On Thu, Mar 14, 2013 at 3:09 PM, Matijn Woudt<tijn...@gmail.com> wrote:

On Thu, Mar 14, 2013 at 7:02 PM, georg<georg.chamb...@telia.com**>
wrote:

Hi,

I have tried to find a way to check if a character string is
possible to
test whether it is convertible to an intger !

any suggestion ?

BR georg



You could use is_numeric for that, though it also accepts floats.

- Matijn



for that type of test I have always used this:

if ( $val == (int)$val ) {

http://www.php.net/manual/en/**language.types.integer.php#**
language.types.integer.casting<http://www.php.net/manual/en/language.types.integer.php#language.types.integer.casting>



I hope you're not serious about this...

When comparing a string and an int, PHP will translate the string to int
too, and of course they will always be equal then.
So:
$a = "abc";
if($a == (int)$a) echo "YES";
else echo "NO";
Will always return YES.

- Matijn


Hmmmm... Interesting. Looking back at my code base where I thought I was
doing that, turns out the final results were not that, but this:

$value = "asdf1234";

if ( $value === (string)intval($value) ) {

Looking back at the OP's request and after a little further searching,
it seems that there might be a better possible solution for what the OP
is requesting.

<?php

$values = array("asdf1234", "123.123", "123");

foreach ( $values AS $value ) {

echo $value;

if ( ctype_digit($value) ) {
echo ' - is all digits';
} else {
echo ' - is NOT all digits';
}
echo '<br />'.PHP_EOL;
}

returns...

asdf1234 - is NOT all digits
123.123 - is NOT all digits
123 - is all digits

http://www.php.net/manual/en/function.ctype-digit.php

An important note:

This function expects a string to be useful, so for example passing in
an integer may not return the expected result. However, also note that
HTML forms will result in numeric strings and not integers. See also the
types section of the manual.

--
Jim


Integers can be negative too: I suspect your test would reject a leading '-'...


--
Peter Ford, Developer                 phone: 01580 893333 fax: 01580 893399
Justcroft International Ltd.                              www.justcroft.com
Justcroft House, High Street, Staplehurst, Kent   TN12 0AH   United Kingdom
Registered in England and Wales: 2297906
Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS

--- End Message ---
--- Begin Message ---
On Fri, Mar 15, 2013 at 3:55 AM, Peter Ford <p...@justcroft.com> wrote:
> On 15/03/13 06:21, Jim Lucas wrote:
>>
>> On 3/14/2013 4:05 PM, Matijn Woudt wrote:
>>>
>>> On Thu, Mar 14, 2013 at 11:44 PM, Jim Lucas <li...@cmsws.com> wrote:
>>>
>>>> On 03/14/2013 11:50 AM, Samuel Lopes Grigolato wrote:
>>>>
>>>>> Something like "if (is_numeric($var)&& $var == floor($var))" will do
>>>>> the
>>>>>
>>>>> trick. I don't know if there's a better (more elegant) way.
>>>>>
>>>>>
>>>>> On Thu, Mar 14, 2013 at 3:09 PM, Matijn Woudt<tijn...@gmail.com> wrote:
>>>>>
>>>>> On Thu, Mar 14, 2013 at 7:02 PM, georg<georg.chamb...@telia.com**>
>>>>>>
>>>>>> wrote:
>>>>>>
>>>>>> Hi,
>>>>>>>
>>>>>>>
>>>>>>> I have tried to find a way to check if a character string is
>>>>>>> possible to
>>>>>>> test whether it is convertible to an intger !
>>>>>>>
>>>>>>> any suggestion ?
>>>>>>>
>>>>>>> BR georg
>>>>>>>
>>>>>>
>>>>>>
>>>>>> You could use is_numeric for that, though it also accepts floats.
>>>>>>
>>>>>> - Matijn
>>>>>>
>>>>>>
>>>>>
>>>> for that type of test I have always used this:
>>>>
>>>> if ( $val == (int)$val ) {
>>>>
>>>> http://www.php.net/manual/en/**language.types.integer.php#**
>>>>
>>>> language.types.integer.casting<http://www.php.net/manual/en/language.types.integer.php#language.types.integer.casting>
>>>>
>>>>
>>>>
>>> I hope you're not serious about this...
>>>
>>> When comparing a string and an int, PHP will translate the string to int
>>> too, and of course they will always be equal then.
>>> So:
>>> $a = "abc";
>>> if($a == (int)$a) echo "YES";
>>> else echo "NO";
>>> Will always return YES.
>>>
>>> - Matijn
>>>
>>
>> Hmmmm... Interesting. Looking back at my code base where I thought I was
>> doing that, turns out the final results were not that, but this:
>>
>> $value = "asdf1234";
>>
>> if ( $value === (string)intval($value) ) {
>>
>> Looking back at the OP's request and after a little further searching,
>> it seems that there might be a better possible solution for what the OP
>> is requesting.
>>
>> <?php
>>
>> $values = array("asdf1234", "123.123", "123");
>>
>> foreach ( $values AS $value ) {
>>
>> echo $value;
>>
>> if ( ctype_digit($value) ) {
>> echo ' - is all digits';
>> } else {
>> echo ' - is NOT all digits';
>> }
>> echo '<br />'.PHP_EOL;
>> }
>>
>> returns...
>>
>> asdf1234 - is NOT all digits
>> 123.123 - is NOT all digits
>> 123 - is all digits
>>
>> http://www.php.net/manual/en/function.ctype-digit.php
>>
>> An important note:
>>
>> This function expects a string to be useful, so for example passing in
>> an integer may not return the expected result. However, also note that
>> HTML forms will result in numeric strings and not integers. See also the
>> types section of the manual.
>>
>> --
>> Jim
>>
>
> Integers can be negative too: I suspect your test would reject a leading
> '-'...


For my money, `is_numeric()` does just what I want.

--- End Message ---
--- Begin Message ---
Have two questions -
1. How to find type of a variable in PHP.
2. How to find the type of an array in PHP.

Please help.


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

On Fri, 2013-03-15 at 09:55 +0000, Kevin Peterson wrote:
> Have two questions -
> 1. How to find type of a variable in PHP.
> 2. How to find the type of an array in PHP.
> 
> Please help.
> 

Use this:
http://php.net/manual/en/function.gettype.php

Regards

Karim

-- 
Karim Geiger

B1 Systems GmbH
Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de
GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537

Attachment: signature.asc
Description: This is a digitally signed message part


--- End Message ---
--- Begin Message ---
Karim Geiger wrote:
Have two questions -
>1. How to find type of a variable in PHP.
>2. How to find the type of an array in PHP.
>
>Please help.
>
Use this:
http://php.net/manual/en/function.gettype.php

BUT - bear in mind that the nice thing about PHP 'arrays' is that they are a not restricted to a single type. The elements of an array can be different types. It's more a 'basket' than a traditional array.

--
Lester Caine - G8HFL
-----------------------------
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk
Rainbow Digital Media - http://rainbowdigitalmedia.co.uk

--- End Message ---
--- Begin Message ---
2013/3/15 Kevin Peterson <qh.res...@gmail.com>

> Have two questions -
> 1. How to find type of a variable in PHP.
>

gettype(), or one of the is_*()-functions. But for me more interesting for
me: Why do you _need_ this?


> 2. How to find the type of an array in PHP.
>

An array is of type array :) is_array() or again gettype().


Can you maybe describe what you want to achieve? In a dynamically typed
language it is rarely _required_, that you know the _concrete_ type.


>
> Please help.
>
>


-- 
github.com/KingCrunch

--- End Message ---
--- Begin Message ---
I have a need to make a pure "display" in a (HTML tagged area defined by) FRAME
now so far I have only succeeded in making output into a frame by landing
a clicked tag to open the new doc (href or src) in a specified frame.
Possibly its not solvable with framework of frames.

( I know, FRAMEs are a dying breed, depressed by HTML society, sorry 
"deprecated"
  possibly my issue is fixable by style-sheets but I havnt gotten that far yet, 
too complex )

tnx for any input
georg

--- End Message ---
--- Begin Message ---
On Fri, Mar 15, 2013 at 5:00 AM, georg <georg.chamb...@telia.com> wrote:
> I have a need to make a pure "display" in a (HTML tagged area defined by) 
> FRAME
> now so far I have only succeeded in making output into a frame by landing
> a clicked tag to open the new doc (href or src) in a specified frame.
> Possibly its not solvable with framework of frames.

Not 100% sure of what you want, but can't you just populate the frames directly?

<frameset rows="10%,*">
  <frame name="upper" src="upperframe.php">
  <frame name="lower" src="lowerframe.php">
</frameset>

the link in the src attribute populates it initially.

You already know how to populate them with links.

> ( I know, FRAMEs are a dying breed, depressed by HTML society, sorry 
> "deprecated"
>   possibly my issue is fixable by style-sheets but I havnt gotten that far 
> yet, too complex )

Frames are not only deprecated, they are unsupported entirely in HTML5
(not that browsers won't continue to display them; just that they
won't validate).

Leap the hurdle and start to look at Web 3.0 stuff with backbone.js,
twitter's bootstrap,  etc.

--- End Message ---
--- Begin Message ---
On 15 Mar 2013 at 11:00, tamouse mailing lists <tamouse.li...@gmail.com> wrote: 

> Frames are not only deprecated, they are unsupported entirely in HTML5
> (not that browsers won't continue to display them; just that they
> won't validate).

Meaning, in other words, that they *are* supported. It's unlikely in any case 
that any feature will ever be removed from a browser.

--
Cheers  --  Tim

--- End Message ---
--- Begin Message ---
Hi, yepp & thnx, so far I have got,
but now im in a situation where I have made 2nice frames one contining the picture (noscroll) and i want to have a quite narrow frame at the side displaying a text, however I want to fill both frames at one mouseclick....... here Im utterly failing :(
for some time now

BR georg

----- Original Message ----- From: "tamouse mailing lists" <tamouse.li...@gmail.com>
To: <php-gene...@lists.php.net>
Sent: Friday, March 15, 2013 12:00 PM
Subject: Re: [PHP] rather a HTML Q; however 2-FRAME


On Fri, Mar 15, 2013 at 5:00 AM, georg <georg.chamb...@telia.com> wrote:
I have a need to make a pure "display" in a (HTML tagged area defined by) FRAME
now so far I have only succeeded in making output into a frame by landing
a clicked tag to open the new doc (href or src) in a specified frame.
Possibly its not solvable with framework of frames.

Not 100% sure of what you want, but can't you just populate the frames directly?

<frameset rows="10%,*">
 <frame name="upper" src="upperframe.php">
 <frame name="lower" src="lowerframe.php">
</frameset>

the link in the src attribute populates it initially.

You already know how to populate them with links.

( I know, FRAMEs are a dying breed, depressed by HTML society, sorry "deprecated" possibly my issue is fixable by style-sheets but I havnt gotten that far yet, too complex )

Frames are not only deprecated, they are unsupported entirely in HTML5
(not that browsers won't continue to display them; just that they
won't validate).

Leap the hurdle and start to look at Web 3.0 stuff with backbone.js,
twitter's bootstrap,  etc.

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



--- End Message ---
--- Begin Message ---
To make things clearer. I already have the frames since earlier and
want to fill then again, so it is not at the "initial filling" of the frames
at "creation".

BR georg
----- Original Message ----- From: "georg" <georg.chamb...@telia.com>
To: "tamouse mailing lists" <tamouse.li...@gmail.com>
Cc: <php-gene...@lists.php.net>
Sent: Friday, March 15, 2013 2:31 PM
Subject: Re: [PHP] rather a HTML Q; however 2-FRAME


Hi, yepp & thnx, so far I have got,
but now im in a situation where I have made 2nice frames one contining the picture (noscroll) and i want to have a quite narrow frame at the side displaying a text, however I want to fill both frames at one mouseclick....... here Im utterly failing :(
for some time now

BR georg

----- Original Message ----- From: "tamouse mailing lists" <tamouse.li...@gmail.com>
To: <php-gene...@lists.php.net>
Sent: Friday, March 15, 2013 12:00 PM
Subject: Re: [PHP] rather a HTML Q; however 2-FRAME


On Fri, Mar 15, 2013 at 5:00 AM, georg <georg.chamb...@telia.com> wrote:
I have a need to make a pure "display" in a (HTML tagged area defined by) FRAME now so far I have only succeeded in making output into a frame by landing
a clicked tag to open the new doc (href or src) in a specified frame.
Possibly its not solvable with framework of frames.

Not 100% sure of what you want, but can't you just populate the frames directly?

<frameset rows="10%,*">
 <frame name="upper" src="upperframe.php">
 <frame name="lower" src="lowerframe.php">
</frameset>

the link in the src attribute populates it initially.

You already know how to populate them with links.

( I know, FRAMEs are a dying breed, depressed by HTML society, sorry "deprecated" possibly my issue is fixable by style-sheets but I havnt gotten that far yet, too complex )

Frames are not only deprecated, they are unsupported entirely in HTML5
(not that browsers won't continue to display them; just that they
won't validate).

Leap the hurdle and start to look at Web 3.0 stuff with backbone.js,
twitter's bootstrap,  etc.

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




--- End Message ---
--- Begin Message ---
On 15 Mar 2013, at 13:34, "georg" <georg.chamb...@telia.com> wrote:

> To make things clearer. I already have the frames since earlier and
> want to fill then again, so it is not at the "initial filling" of the frames
> at "creation".

You want one action to change the content in two frames? For that you'll need 
to use Javascript, or reload the parent frame, neither of which involve PHP.

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/

--- End Message ---
--- Begin Message ---
Actually I think you are right;

what I would have liked (as a natural extension of the depression....:)
is actually a <FRAME> tag that stands without the <FRAMESET>
and which as target="framename" instead of the frame defining name="framename"
and which just displayed the src in that frame (immediatly as it does today)

Im fairly new to PHP so Im bound to bounce into some walls, tnx.

BR georg

----- Original Message ----- From: "Stuart Dallas" <stu...@3ft9.com>
To: "georg" <georg.chamb...@telia.com>
Cc: "PHP General" <>
Sent: Friday, March 15, 2013 2:38 PM
Subject: Re: [PHP] rather a HTML Q; however 2-FRAME


On 15 Mar 2013, at 13:34, "georg" <georg.chamb...@telia.com> wrote:

To make things clearer. I already have the frames since earlier and
want to fill then again, so it is not at the "initial filling" of the frames
at "creation".

You want one action to change the content in two frames? For that you'll need to use Javascript, or reload the parent frame, neither of which involve PHP.

-Stuart

--
Stuart Dallas
3ft9 Ltd
http://3ft9.com/=
--- End Message ---
--- Begin Message ---
On Fri, Mar 15, 2013 at 9:11 AM, georg <georg.chamb...@telia.com> wrote:
> Actually I think you are right;
>
> what I would have liked (as a natural extension of the depression....:)
> is actually a <FRAME> tag that stands without the <FRAMESET>
> and which as target="framename" instead of the frame defining
> name="framename"
> and which just displayed the src in that frame (immediatly as it does today)

Maybe you want an IFRAME (Inline Frame) instead of FRAMESET/FRAME?


>
> Im fairly new to PHP so Im bound to bounce into some walls, tnx.
>
> BR georg
>
> ----- Original Message ----- From: "Stuart Dallas" <stu...@3ft9.com>
> To: "georg" <georg.chamb...@telia.com>
> Cc: "PHP General" <>
> Sent: Friday, March 15, 2013 2:38 PM
>
> Subject: Re: [PHP] rather a HTML Q; however 2-FRAME
>
>
> On 15 Mar 2013, at 13:34, "georg" <georg.chamb...@telia.com> wrote:
>
>> To make things clearer. I already have the frames since earlier and
>> want to fill then again, so it is not at the "initial filling" of the
>> frames
>> at "creation".
>
>
> You want one action to change the content in two frames? For that you'll
> need to use Javascript, or reload the parent frame, neither of which involve
> PHP.
>
> -Stuart
>
> --
> Stuart Dallas
> 3ft9 Ltd
> http://3ft9.com/=
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

--- End Message ---
--- Begin Message ---
On 3/15/2013 10:11 AM, georg wrote:
Actually I think you are right;

what I would have liked (as a natural extension of the depression....:)
is actually a <FRAME> tag that stands without the <FRAMESET>
and which as target="framename" instead of the frame defining
name="framename"
and which just displayed the src in that frame (immediatly as it does
today)

Im fairly new to PHP so Im bound to bounce into some walls, tnx.

BR georg

And apparently new to html as well if you want to use frames still  :)
Why not learn "just a little" css and html and develop something more current that you won't be re-visiting down the road some time and changing?
--- End Message ---
--- Begin Message ---
Hi Georg,

On Thu, 2013-03-14 at 23:10 +0100, georg wrote:
> hello,
> annyone knows of some good PHP context editor freeware ?
> (tired of missing out on trivials like ; )

I don't know exactly what you mean by a context editor but if you want
an editor with syntax highlighting try eclipse for an complete IDE
(Multiplatform), notepad++ on Windows, textwrangler on Mac or vim on
Linux

Regards

-- 
Karim Geiger

B1 Systems GmbH
Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de
GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537

Attachment: signature.asc
Description: This is a digitally signed message part


--- End Message ---
--- Begin Message ---
2013/3/15 Karim Geiger <gei...@b1-systems.de>

> Hi Georg,
>
> On Thu, 2013-03-14 at 23:10 +0100, georg wrote:
> > hello,
> > annyone knows of some good PHP context editor freeware ?
> > (tired of missing out on trivials like ; )
>
> I don't know exactly what you mean by a context editor but if you want
> an editor with syntax highlighting try eclipse for an complete IDE
> (Multiplatform), notepad++ on Windows, textwrangler on Mac or vim on
> Linux
>

Or PhpStorm on Linux (multiplatform)  :) Or Netbeans on Linux
(multiplatform too). Or gedit on Gnome/Linux, or or or ...
"vim" is not the end of what can a linux desktop can provide :D


>
> Regards
>
> --
> Karim Geiger
>
> B1 Systems GmbH
> Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de
> GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537
>



-- 
github.com/KingCrunch

--- End Message ---
--- Begin Message --- I have inherited a mess of a home-grown PHP framework that literally fills the error_log with 100's of thousands of messages each day. First order of business was rotating the logs, now we are working through each error to solve them. This is a fairly basic error, but I for the life of me cannot remember what the solution is.

I have a recursive function that reads from XML files and replaces xi: include directives. It looks like this -

function includeXML($file, $locale, $url, $level = 1) {
    // stuff
    while(($line = fgets($fp)) !== false) {
        if($pos === false) {
            $xml .= $line;
        } else {
includeXML('repository/' . $included, $locale, (int)$level + $pos - 1);
        }
    }
}

Why do I get the notice that $xml is an undefined index? I do not want to suppress the notice, I just want to take care of it properly. I attempted setting $xml within the function but then the whole function fails for some reason in the depths of this hideous framework. Can anyone provide any insight? TVMIA!
--- End Message ---
--- Begin Message ---
Hi,

Two questions:
Where is $xml defined and where is $pos defined?

HTH

Kind regards/met vriendelijke groet,

Serge Fonville

http://www.sergefonville.nl

Convince Microsoft!
They need to add TRUNCATE PARTITION in SQL Server
https://connect.microsoft.com/SQLServer/feedback/details/417926/truncate-partition-of-partitioned-table


2013/3/15 Jay Blanchard <jay.blanch...@sigmaphinothing.org>

> I have inherited a mess of a home-grown PHP framework that literally fills
> the error_log with 100's of thousands of messages each day. First order of
> business was rotating the logs, now we are working through each error to
> solve them. This is a fairly basic error, but I for the life of me cannot
> remember what the solution is.
>
> I have a recursive function that reads from XML files and replaces xi:
> include directives. It looks like this -
>
> function includeXML($file, $locale, $url, $level = 1) {
>     // stuff
>     while(($line = fgets($fp)) !== false) {
>         if($pos === false) {
>             $xml .= $line;
>         } else {
>             includeXML('repository/' . $included, $locale, (int)$level +
> $pos - 1);
>         }
>     }
> }
>
> Why do I get the notice that $xml is an undefined index? I do not want to
> suppress the notice, I just want to take care of it properly. I attempted
> setting $xml within the function but then the whole function fails for some
> reason in the depths of this hideous framework. Can anyone provide any
> insight? TVMIA!
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
[snip]
Two questions:
Where is $xml defined and where is $pos defined?

[/snip]

$xml is defined in other functions, just not in this function. $pos is irrelevant to the question - it is just the string position within the file.
--- End Message ---
--- Begin Message ---
So basically, $xml is out of scope for this function and you are appending
to a nonexisting variable?

Kind regards/met vriendelijke groet,

Serge Fonville

http://www.sergefonville.nl

Convince Microsoft!
They need to add TRUNCATE PARTITION in SQL Server
https://connect.microsoft.com/SQLServer/feedback/details/417926/truncate-partition-of-partitioned-table


2013/3/15 Jay Blanchard <jay.blanch...@sigmaphinothing.org>

> [snip]
>
>  Two questions:
>> Where is $xml defined and where is $pos defined?
>>
>>  [/snip]
>
> $xml is defined in other functions, just not in this function. $pos is
> irrelevant to the question - it is just the string position within the file.
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
Jay Blanchard wrote:
I have inherited a mess of a home-grown PHP framework that literally fills the
error_log with 100's of thousands of messages each day. First order of business
was rotating the logs, now we are working through each error to solve them. This
is a fairly basic error, but I for the life of me cannot remember what the
solution is.

I have a recursive function that reads from XML files and replaces xi: include
directives. It looks like this -

function includeXML($file, $locale, $url, $level = 1) {
     // stuff

$xml = '';
Should work here ...
Since the call below is ADDING to $xml you do need something existing to add to so what does that give?

     while(($line = fgets($fp)) !== false) {
         if($pos === false) {
             $xml .= $line;
         } else {
             includeXML('repository/' . $included, $locale, (int)$level + $pos -
1);
         }
     }
}

Why do I get the notice that $xml is an undefined index? I do not want to
suppress the notice, I just want to take care of it properly. I attempted
setting $xml within the function but then the whole function fails for some
reason in the depths of this hideous framework. Can anyone provide any insight?
TVMIA!

--
Lester Caine - G8HFL
-----------------------------
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk
Rainbow Digital Media - http://rainbowdigitalmedia.co.uk

--- End Message ---
--- Begin Message ---
On 15 Mar 2013 at 13:10, Jay Blanchard <jay.blanch...@sigmaphinothing.org> 
wrote: 

> I have inherited a mess of a home-grown PHP framework that literally
> fills the error_log with 100's of thousands of messages each day. First
> order of business was rotating the logs, now we are working through each
> error to solve them. This is a fairly basic error, but I for the life of
> me cannot remember what the solution is.
>
> I have a recursive function that reads from XML files and replaces xi:
> include directives. It looks like this -
>
> function includeXML($file, $locale, $url, $level = 1) {
>     // stuff
>     while(($line = fgets($fp)) !== false) {
>         if($pos === false) {
>             $xml .= $line;
>         } else {
>             includeXML('repository/' . $included, $locale, (int)$level
> + $pos - 1);
>         }
>     }
> }
>
> Why do I get the notice that $xml is an undefined index?

Because it's undefined. So is $pos. From what you've written above, both are 
local to includeXML. But neither is passed in as a parameter, nor is global. 
You can't initialise it within the function, it seems to me.

If $xml is supposed to be appended to and grown as you recurse up and down, 
then you have two choices:

1) Make them global
2) Pass both as extra parameters to includeXML

In both cases, each needs to be initialised before the first call to the 
recursive function

Solution (1)
============

$xml = '';
$pos = 0;    // Presumably.
includeXML ($file, $locale, $url, 1);

...

function includeXML ($file, $locale, $url, $level = 1) {

    global  $xml, $pos;

    // stuff
    while(($line = fgets($fp)) !== false) {
        if($pos === false) {
            $xml .= $line;
        } else {
            includeXML ('repository/' . $included, $locale, (int)$level
+ $pos - 1);
        }
    }
}

Solution (2)
============

$xml = '';
$pos = 0;    // Presumably.
includeXML ($xml, $pos, $file, $locale, $url, 1);

...

function includeXML (&$xml, $pos, $file, $locale, $url, $level = 1) {    // 
Note the & on the first parameter
    // stuff
    while(($line = fgets($fp)) !== false) {
        if($pos === false) {
            $xml .= $line;
        } else {
            includeXML ($xml, $pos, 'repository/' . $included, $locale, 
(int)$level
+ $pos - 1);
        }
    }
}


BTW it seems to me that you'll have the same problem with $included unless 
there's other code in includeXML that you've omitted.

--
Cheers  --  Tim

--- End Message ---
--- Begin Message ---
[snip]
function includeXML($file, $locale, $url, $level = 1) {
     // stuff

$xml = '';
Should work here ...
Since the call below is ADDING to $xml you do need something existing to add to so what does that give?
[/snip]

Thanks Lester, that worked. I had just put that in the wrong place. *slaps forehead*
--- End Message ---
--- Begin Message ---
At 09:44 PM 3/14/2013, tamouse mailing lists wrote:

>If you are delivering files to a (human) user via their browser, by whatever 
>mechanism, that means someone can write a script to scrape them.

That script, however, would have to be running on my host system in order to 
access the script which actually delivers the file, as the latter script is 
located outside of the web root.

Dale H. Cook, Market Chief Engineer, Centennial Broadcasting, 
Roanoke/Lynchburg, VA
http://plymouthcolony.net/starcityeng/index.html  


--- End Message ---
--- Begin Message ---
On 15 Mar 2013, at 13:11, "Dale H. Cook" <webmas...@plymouthcolony.net> wrote:

> At 09:44 PM 3/14/2013, tamouse mailing lists wrote:
> 
>> If you are delivering files to a (human) user via their browser, by whatever 
>> mechanism, that means someone can write a script to scrape them.
> 
> That script, however, would have to be running on my host system in order to 
> access the script which actually delivers the file, as the latter script is 
> located outside of the web root.

If a browser can get at it then a spider can get at it. All this talk of the 
web root is daft. Unless your site is being specifically targeted (highly 
unlikely) then it automated systems that are downloading your content and 
offering it on other websites. The only way such a system can discover content 
is if it's linked from somewhere. Whether that link uses a script that inside 
or outside the web root is completely irrelevant.

Since copies of the content is now out there, anything you add now to protect 
your content is not going to get it back. You'll have to pursue legal avenues 
to prevent it being made available, and that's usually prohibitively expensive.

Based on your description of your users, you have the age-old dilemma of 
balancing ease of use and security. The more you try to protect the content 
from these spiders the harder you'll make it for users.

Here's what I'd do: make sure your details and your website info are plastered 
across every page of the PDF files. Make sure that where copies exist it's 
going to be obvious where the content came from. It sounds like you don't 
charge for the content (this problem wouldn't exist if you did), so you have 
nothing financial to gain from controlling these external copies, other than 
wanting it to be clear from whence it came and where to find more.

At the end of the day the question is this: would you rather control access to 
your creation (in which case charge a nominal fee for it), or would you prefer 
that it (and your name/cause) gets in to as many hands as possible. As a 
professional photographer I made the latter choice a long time ago and haven't 
looked back since.

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/

--- End Message ---
--- Begin Message ---
At 09:27 AM 3/15/2013, Stuart Dallas wrote:

>You'll have to pursue legal avenues to prevent it being made available, and 
>that's usually prohibitively expensive.

Not necessarily. Most of the host systems for the scraper sites are responsive 
to my complaints. Even if a site owner will not respond to a DMCA takedown 
notice the host system will often honor that notice, and other site owners and 
hosts will back down when notified of my royalty rates for the use of my files 
by a commercial site.

>At the end of the day the question is this: would you rather control access to 
>your creation (in which case charge a nominal fee for it), or would you prefer 
>that it (and your name/cause) gets in to as many hands as possible.

I merely wish to try to prevent commercial sites from profiting from my work 
without my permission. I am in the process of registering the copyright for my 
files with LOC, as my attorneys have advised. That will give my attorneys 
ammunition.

Dale H. Cook, Member, NEHGS and MA Society of Mayflower Descendants;
Plymouth Co. MA Coordinator for the USGenWeb Project
Administrator of http://plymouthcolony.net 


--- End Message ---
--- Begin Message ---
In case you haven't read this already... http://theoatmeal.com/blog/funnyjunk

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

I have a trouble with PDO transactions.

I would like to start using transactions, but I am not familiar with it. I
have got a 'There is no active transaction' exception, however, I am using
beginTransaction method, and also I have set PDO::ATTR_AUTOCOMMIT to false
right after connecting to the database.
In my whole code I have used the commit method only once.

Between beginTransaction and commit methods, as far as I know, I did not
use anything that could activate auto-commit. In my test code, there is
only an exec method of PDO, and an execute of PDOStatement. Maybe one of
these activated auto-commit?

And what are the possible commands which are able to activate auto-commit?
I know that the commit method can do that, but - as I already wrote - I
have issued it only once, and it is in the destructor of a singleton class.

So what could be the problem?

--- End Message ---

Reply via email to