php-general Digest 21 Feb 2010 14:12:08 -0000 Issue 6601

Topics (messages 302238 through 302245):

Re: Excel Spreadsheets and PHP
        302238 by: Nathan Rixham

Re: Advice on maintaining public and private files
        302239 by: Nathan Rixham
        302242 by: Al
        302245 by: Kim Madsen

PHP, PHPMailer and SMTP Server
        302240 by: gato chlr
        302241 by: Per Jessen

Re: Pre/Post inc (Was array conversion)
        302243 by: Adam Richardson
        302244 by: clancy_1.cybec.com.au

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 ---
Bastien Koert wrote:
> You can also create an htnl table and excel will happily handle that as well.
> 
> The real trick is to get IE to accept the stream as a file download. I
> find that I need to save the file first and the push the file down.
> 

+1 this approach; Excel is HTTP aware and you can simply plumb in the
URL of an HTML table and excel will do the rest; it works v well; saves
tonnes of work and means you can do nice little things like importing
SPARQL over HTTP queries straight in to excel - and then make nice pivot
[1] views of the data, all in a couple of minutes.

[1] http://www.getpivot.com/

--- End Message ---
--- Begin Message ---
Kim Madsen wrote:
> Michael Stroh wrote on 19/02/2010 19:19:
>> I have a site I'm working on with some data that I want to be
>> readable by anyone, but some files that I want to keep hidden from
>> outside users. Here is an example of my file structure.
>>
>> /products/data1/item_1/data.txt 
>> /products/data2/item_2/data.txt
> 
> since no one has suggested it then... if you're on an Apache webserver
> use a .htaccess file in data2 which contains:
> 
> Deny from all
> Allow from none
> 
> That will do the trick and PHP can still fetch the files in data2 and
> serve it to the user.
> 

Glad you said this; I'd been waiting to see if anybody would - certainly
there is no quicker or easier way to solve this particular problem.

Also worth adding that you can easily password protect the directories
too using HTTP authorisation [1] (and even hook it in to LDAP or
suchlike very simply).

It's the curse of the PHP developer to try and use PHP to solve every
problem - we all fall fowl of it often (I've wasted years doing things
in PHP that really should have been done with a different tech).

[1] http://httpd.apache.org/docs/2.0/howto/auth.html

Regards!

Nathan

--- End Message ---
--- Begin Message --- I use Kim's solution and take it one step forward. Htacces files can get lost or corrupted, so....


In my  config file I have the text string.

//region******** htaccess file text ********
// Code writes to /db folder; Admin mode checks file existence and text; replaces with this if different.

$htaccessText = <<<hta
# Prevent Direct Access to MiniRegDB DB Files
<Files *>
Order Deny,Allow
Deny from all
</Files>
hta;
//endregion

In my main control file I call this function

/**
* checkHTaccessFile()
*
* Checks and restores htaccess  Prevent Direct Access to MiniRegDB Program Files
*
* @param mixed $htaccessText in config file
* @return
*/
function checkHTaccessFile($htaccessText)
{
if(file_exists(MINIREG_DATA_DIR . '.htaccess') && file_get_contents(MINIREG_DATA_DIR . '.htaccess') == $htaccessText) return true;

    file_put_contents(MINIREG_DATA_DIR . '.htaccess', $htaccessText);
    return true;
}


On 2/20/2010 4:05 AM, Kim Madsen wrote:
Michael Stroh wrote on 19/02/2010 19:19:
I have a site I'm working on with some data that I want to be
readable by anyone, but some files that I want to keep hidden from
outside users. Here is an example of my file structure.

/products/data1/item_1/data.txt
 > /products/data2/item_2/data.txt

since no one has suggested it then... if you're on an Apache webserver
use a .htaccess file in data2 which contains:

Deny from all
Allow from none

That will do the trick and PHP can still fetch the files in data2 and
serve it to the user.


--- End Message ---
--- Begin Message ---
Al wrote on 20/02/2010 19:30:
I use Kim's solution and take it one step forward. Htacces files can get lost or corrupted, so....

No solution to that problem as I see it.

In my  config file I have the text string.

I like the idea, but what if this file is never accessed?

--
Kind regards
Kim Emax - masterminds.dk

--- End Message ---
--- Begin Message ---
Hi,to every body

i'm buildding a little application, for now i'm working in my localhost.
I need to send a mail and i need to use phpmailer, but..
when i send a mail using phpMailer it tooks a lot of time, i suppose it is
because the bandwidth (128kbps and 3 PCs connected in the LAN). any way i
need to solve it. thinking a few i have found the next posible solutions:

*install a SMTP server in my machine, so , when the phpMailer sends a mail ,
there is no routers to jump , and no need to consume bandwith, the PHP
application does keep freezed "waiting for...".

*use multithreading in php , how? creating a thread to send the mail, and
the application can show me the next screen while the sender thread is
working, but as long as i readed , it does not exists. I have found a
solution in Linux by using forke function,  "damn" i'm working on Windows.
Like all, i supose there is a way to make it works in Windows.

*Ask to my php comunity , explain my problem, and my posible solutions, and
receive a good feeback in order to know wichone is better solution, and
listen if there is other solutions



so i will appreciate the contributions, thanks to every body

--- End Message ---
--- Begin Message ---
gato chlr wrote:

> Hi,to every body
> 
> i'm buildding a little application, for now i'm working in my
> localhost. I need to send a mail and i need to use phpmailer, but..
> when i send a mail using phpMailer it tooks a lot of time, i suppose
> it is because the bandwidth (128kbps and 3 PCs connected in the LAN).
> any way i need to solve it. 

Unless you're sending very large emails, it's more likely to be a DNS
problem. 

> thinking a few i have found the next 
> posible solutions:
> 
> *install a SMTP server in my machine, so , when the phpMailer sends a
> mail , there is no routers to jump , and no need to consume bandwith,
> the PHP application does keep freezed "waiting for...".

Apart from fixing your DNS problem, this is by far the best solution.
With a local mailserver, sendmail simply drops new mails into its
queue, and that's it.  


/Per


-- 
Per Jessen, Zürich (3.5°C)


--- End Message ---
--- Begin Message ---
On Sat, Feb 20, 2010 at 11:10 AM, Nathan Rixham <nrix...@gmail.com> wrote:

> Richard Quadling wrote:
> > On 20 February 2010 11:18,  <clanc...@cybec.com.au> wrote:
> >> Or:
> >>
> >> $a = array ('Cats', 'white', 'Dogs', 'black', 'Mice', 'grey', 'Camels',
> 'brown');
> >> $b = '';                                // Just in case it has some
> leftover value
> >> $k = 2* (int) (count ($a)/2);   // ensure even no of terms
> >> $i = 0; while ($i < $k)
> >>        {
> >>        $b[$a[$i++]] = $a[$i++];  // ***
> >>        }
> >>
> >> And this works:
> >> $i = 0; $k = array_keys($b);
> >> while ($i < count($b)) {        echo '<h5>'.$i.': '.$k[$i].' = '.
> $b[$k[$i++]].'</h5>'; }
> >>
> >> 0: Cats = white
> >> 1: Dogs = black
> >> 2: Mice = grey
> >> 3: Camels = brown
> >>
> >> ( *** I have always been wary of using statements like this because I
> was unsure when the
> >> incrementing would occur, so I tried it.)
> >>
> >> Clancy
> >
> >
> > <?php
> > $i = 10;
> > echo $i++; // Shows 10 and $i becomes 11
> > echo ++$i; // $i becomes 12 and 12 is shown.
> > ?>
> >
> > Post increment and pre increment.
> >
> > No need to be "wary" of them.
> >
> > http://docs.php.net/manual/en/language.operators.increment.php
> >
>
> Expanding on what Richard says; there does seem to be a growing number
> of people who haven't stopped to learn the very basics of PHP (or
> languages in general).
>
> I'd strongly recommend that all those in doubt over the basics take a
> few hours out to (re-)familiarise themselves; and there's no finer
> resource to do this than the php manual [1]
>
> You'll notice the manual goes as follows:
> # Basic syntax
> # Types
> # Variables
> # Constants
> # Expressions
> # Operators
> # Control Structures
> # Functions
> ... more
>
> And that's the order in which you should learn; in short you can't
> really program or script without knowing basics through control structures.
>
> Do hope this mail doesn't sound condescending in any way; as it's meant
> with the best intentions and really will make you're (working) life a
> lot easier. I myself still refer back to these base sections
> periodically, and every time I do - a new detail pops out that makes
> something easier.
>
> [1] http://docs.php.net/manual/en/langref.php
>
> Many Regards,
>
> Nathan
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Clarifying what Clancy specifically said:

>> ( *** I have always been wary of using statements like this because I was
unsure when the
>> incrementing would occur, so I tried it.)

The asterisks inform us he was speaking about the first example, and the
language informs us he was speaking about the statement, not the increment
operator, itself.

>> $b[$a[$i++]] = $a[$i++];  // ***

It's actually quite a clever implementation of the algorithm request that
prompted this thread, and because of it's uniqueness, (incrementing a
variable multiple times within the same statement on both sides of the '='),
I don't this reflects that Clancy "stopped to learn the very basics of PHP."
 Actually, Clancy taking the time to try something to better learn the
language (just for the sake of coding fun, no less) reflects the desire to
learn new things, and that's exactly the type of person I hope is drawn to
the PHP community.

Thanks for the example, Clancy :)

Adam

-- 
Nephtali:  PHP web framework that functions beautifully
http://nephtaliproject.com

--- End Message ---
--- Begin Message ---
On Sat, 20 Feb 2010 17:44:00 -0500, you wrote:

>On Sat, Feb 20, 2010 at 11:10 AM, Nathan Rixham <nrix...@gmail.com> wrote:
>
>> Richard Quadling wrote:
>> > On 20 February 2010 11:18,  <clanc...@cybec.com.au> wrote:
>> >> Or:
>> >>
>> >> $a = array ('Cats', 'white', 'Dogs', 'black', 'Mice', 'grey', 'Camels',
>> 'brown');
>> >> $b = '';                                // Just in case it has some
>> leftover value
>> >> $k = 2* (int) (count ($a)/2);   // ensure even no of terms
>> >> $i = 0; while ($i < $k)
>> >>        {
>> >>        $b[$a[$i++]] = $a[$i++];  // ***
>> >>        }
>> >>
>> >> And this works:
>> >> $i = 0; $k = array_keys($b);
>> >> while ($i < count($b)) {        echo '<h5>'.$i.': '.$k[$i].' = '.
>> $b[$k[$i++]].'</h5>'; }
>> >>
>> >> 0: Cats = white
>> >> 1: Dogs = black
>> >> 2: Mice = grey
>> >> 3: Camels = brown
>> >>
>> >> ( *** I have always been wary of using statements like this because I
>> was unsure when the
>> >> incrementing would occur, so I tried it.)
>> >>
>> >> Clancy
>> >
>> >
>> > <?php
>> > $i = 10;
>> > echo $i++; // Shows 10 and $i becomes 11
>> > echo ++$i; // $i becomes 12 and 12 is shown.
>> > ?>
>> >
>> > Post increment and pre increment.
>> >
>> > No need to be "wary" of them.
>> >
>> > http://docs.php.net/manual/en/language.operators.increment.php
>> >
>>
>> Expanding on what Richard says; there does seem to be a growing number
>> of people who haven't stopped to learn the very basics of PHP (or
>> languages in general).
>>
>> I'd strongly recommend that all those in doubt over the basics take a
>> few hours out to (re-)familiarise themselves; and there's no finer
>> resource to do this than the php manual [1]
>>
>> You'll notice the manual goes as follows:
>> # Basic syntax
>> # Types
>> # Variables
>> # Constants
>> # Expressions
>> # Operators
>> # Control Structures
>> # Functions
>> ... more
>>
>> And that's the order in which you should learn; in short you can't
>> really program or script without knowing basics through control structures.
>>
>> Do hope this mail doesn't sound condescending in any way; as it's meant
>> with the best intentions and really will make you're (working) life a
>> lot easier. I myself still refer back to these base sections
>> periodically, and every time I do - a new detail pops out that makes
>> something easier.
>>
>> [1] http://docs.php.net/manual/en/langref.php
>>
>> Many Regards,
>>
>> Nathan
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>Clarifying what Clancy specifically said:
>
>>> ( *** I have always been wary of using statements like this because I was
>unsure when the
>>> incrementing would occur, so I tried it.)
>
>The asterisks inform us he was speaking about the first example, and the
>language informs us he was speaking about the statement, not the increment
>operator, itself.
>
>>> $b[$a[$i++]] = $a[$i++];  // ***
>
>It's actually quite a clever implementation of the algorithm request that
>prompted this thread, and because of it's uniqueness, (incrementing a
>variable multiple times within the same statement on both sides of the '='),
>I don't this reflects that Clancy "stopped to learn the very basics of PHP."
> Actually, Clancy taking the time to try something to better learn the
>language (just for the sake of coding fun, no less) reflects the desire to
>learn new things, and that's exactly the type of person I hope is drawn to
>the PHP community.
>
>Thanks for the example, Clancy :)
>
>Adam

Thanks, Adam.

I started programming before there were any manuals (or classes), and I had to 
jump in at
the deep end. I do like to know how things work, but the days when you could 
make your own
complete commented disassembly of the operating system (as I did for CP/M) are 
long since
gone, and it is no longer possible for any single person to have even a 
reasonable working
knowledge of how all the programs on his computer operate. I regret I have to 
admit that
it is now beyond me to have a working familiarity even with the programs I need 
for
webpage design -- PHP, HTML, CSS and  Javascript, let alone trying to throw in 
C++, Apache
& Unix.  Also questions like this tend to come up when I'm in the middle of 
implementing
something complicated, so usually I take the easy way out, instead of taking 
the time off
to try to answer the question.

The particular case which prompted my comment was the one where you want to 
copy part of
one array into the corresponding elements of another array. Should you write:

$i = 0; $j=count($a); while ($i < $j) { $b[$i] = $a[$i++]; }    OR

$i = 0; $j=count($a); while ($i < $j) { $b[$i++] = $a[$i]; }

Surprisingly (to me) the answer is neither. (Assuming $j = 5) the first gives 
$b[1] =
$a[0], with $b[0] undefined, while the second gives $b[0] = $a[1], with $b[4] 
undefined. 

Experiment shows that you can either be safe, as I have always done, and write:

$i = 0; $j=count($a); while ($i < $j) { $b[$i] = $a[$i]; ++$i; }

or you can write:

$i = -1; $j=count($a) - 1; while ($i < $j) { $b[++$i] = $a[$i]; }

This seemed moderately logical, but then I found you can also write: 

$i = -1; $j=count($a) - 1; while ($i < $j) { $b[$i] = $a[++$i]; }

I think I will stick to the safe way!


--- End Message ---

Reply via email to