php-general Digest 26 Apr 2012 12:15:44 -0000 Issue 7790

Topics (messages 317682 through 317694):

Re: Best PHP Template System
        317682 by: Yared Hufkens
        317683 by: Willie
        317693 by: Simon Schick

Re: Find/count different word in a text
        317684 by: Ken Robinson

Serving a .dmg via readfile?
        317685 by: Brian Dunning
        317686 by: Tommy Pham
        317687 by: D. Dante Lorenso
        317691 by: Tommy Pham

date() confustion
        317688 by: Nathan Nobbe
        317689 by: Simon J Welsh
        317690 by: Nathan Nobbe
        317692 by: marco.behnke.biz

Should I check imput for bad chars in this case?
        317694 by: mirrys.net

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 ---
Why use an external engine which slows your scripts down to do something which 
can easily be done by PHP itself? PHP is imho the best template engine for PHP.
With PHP 5.4, it became even easier because <?=$do->somestuff()?> can be used 
without short_open_tag enabled.
However, you always schould divide UI and backend.

--- Ursprüngl. Mitteilung ---
Von: Willie Matthews
Gesend.:  25.04.2012, 23:48 
An: PHP Mailinglist
Betreff: [PHP] Best PHP Template System


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I have been looking at Smarty Template Engine. The only reason I don't
like it is because it is really slow when there are a bunch of results
for pagination.

Question is, is there something out there that is a lot faster with
pagination built into it? Also with the features of Smarty Template
Engine?

- -- 
Willie Matthews
matthews.wil...@gmail.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.17 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJPmHE9AAoJEPyaSMdprRSF+swH/jkXqfzG+uHE/g7HleLnRIa+
Ld0QYCIXPA1xdv5yPl3HndxPkMeCbvmqPCcdCchQR+2QGV2vOi/P+LycJbh01jb0
ht1BGb+MsOikyT+sNn2VYT1kjKENwZ3VJ4tsjTaGZl9Si98NZGAhCdzAhvkIvB8t
xavbA8eX7y6fKpaGMmV5fOfPDSxavLMy0T7ox2mmLo7UBFcjRyd+Icghdd7rSK34
WH8Wd/nhpcX4E/zCc0D1zEnfzWP/Z7yS0GJi/sLSGpZcs7AyAvQV60XKCSuABBRf
z23n0wrdSmgjbahGFalmog+9u5JxceCxwQ9ZT4tzOgoihLwhwZCUYFxyaWv5jyI=
=jMqu
-----END PGP SIGNATURE-----

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



--- End Message ---
--- Begin Message ---
Point taken. I will try to learn without the Template Engine! Thanks a lot
Yared!

On Wed, Apr 25, 2012 at 3:07 PM, Yared Hufkens <y4...@yahoo.de> wrote:

> Why use an external engine which slows your scripts down to do something
> which can easily be done by PHP itself? PHP is imho the best template
> engine for PHP.
> With PHP 5.4, it became even easier because <?=$do->somestuff()?> can be
> used without short_open_tag enabled.
> However, you always schould divide UI and backend.
>
> --- Ursprüngl. Mitteilung ---
> Von: Willie Matthews
> Gesend.:  25.04.2012, 23:48
> An: PHP Mailinglist
> Betreff: [PHP] Best PHP Template System
>
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> I have been looking at Smarty Template Engine. The only reason I don't
> like it is because it is really slow when there are a bunch of results
> for pagination.
>
> Question is, is there something out there that is a lot faster with
> pagination built into it? Also with the features of Smarty Template
> Engine?
>
> - --
> Willie Matthews
> matthews.wil...@gmail.com
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v2.0.17 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iQEcBAEBAgAGBQJPmHE9AAoJEPyaSMdprRSF+swH/jkXqfzG+uHE/g7HleLnRIa+
> Ld0QYCIXPA1xdv5yPl3HndxPkMeCbvmqPCcdCchQR+2QGV2vOi/P+LycJbh01jb0
> ht1BGb+MsOikyT+sNn2VYT1kjKENwZ3VJ4tsjTaGZl9Si98NZGAhCdzAhvkIvB8t
> xavbA8eX7y6fKpaGMmV5fOfPDSxavLMy0T7ox2mmLo7UBFcjRyd+Icghdd7rSK34
> WH8Wd/nhpcX4E/zCc0D1zEnfzWP/Z7yS0GJi/sLSGpZcs7AyAvQV60XKCSuABBRf
> z23n0wrdSmgjbahGFalmog+9u5JxceCxwQ9ZT4tzOgoihLwhwZCUYFxyaWv5jyI=
> =jMqu
> -----END PGP SIGNATURE-----
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 

Willie Matthews
matthews.wil...@gmail.com

--- End Message ---
--- Begin Message ---
On Thu, Apr 26, 2012 at 12:07 AM, Yared Hufkens <y4...@yahoo.de> wrote:
>
> Why use an external engine which slows your scripts down to do something
> which can easily be done by PHP itself? PHP is imho the best template engine
> for PHP.
> With PHP 5.4, it became even easier because <?=$do->somestuff()?> can be
> used without short_open_tag enabled.
> However, you always schould divide UI and backend.
>

Hi,

If you like to write an xml-template by having purely xml, you could
also use OPT (Open Power Template).

You can f.e. add a attribute to a tag by decision by writing this code:

<div>
    <opt:attribute name="class" value="highlight" opt:if="$highlightDiv"/>
    Content
</div>

Feels a bit cleaner to me than writing

<div <?php if ($highlightDiv) : ?>class="highlight"<?php endif; ?>>
    Content
</div>

--- End Message ---
--- Begin Message ---
At 12:59 PM 4/25/2012, Karl-Arne Gjersøyen wrote:
Hello again.
I am looking for a way to find and count different word in a text..
I am thinking on save the text as array and iterate through the array.
Then I like to register all different words in the text.
For example. If bread is used more than one time, I will not count it.
After the check were I have found single (one) word of every words, I
count it and tell how many different word that is in the text.

Is this difficult to do? Can you give me a hint for were I shall look
on www.php.net for a solution to fix this problem? What function am I
in need of?

I would use a combination of the functions str_word_count and array_count_values.

<?php
$str = "This is a test of word counting and this sentence repeats words a a a a a is is is is";
print_r(array_count_values(str_word_count($str, 1)));
?>

Ken Robinson
--- End Message ---
--- Begin Message ---
Hey all - I'm having no luck serving a .dmg from my online store. I stripped 
down the code to just the following to debug, but no matter what I get a 
zero-byte file served:

  header('Content-Type: application/x-apple-diskimage');   // also tried 
octet-stream
  header('Content-Disposition: attachment; filename="My Cool Image.dmg"');
  $size = filesize('/var/www/mypath/My Cool Image.dmg');
  header('Content-Length: '.$size);
  readfile('/var/www/mypath/My Cool Image.dmg');

This same code works for a number of other file types that I serve: bin, zip, 
pdf. Any suggestions? Professor Google is not my friend.

--- End Message ---
--- Begin Message ---
On Wed, Apr 25, 2012 at 8:54 PM, Brian Dunning <br...@briandunning.com> wrote:
> Hey all - I'm having no luck serving a .dmg from my online store. I stripped 
> down the code to just the following to debug, but no matter what I get a 
> zero-byte file served:
>
>  header('Content-Type: application/x-apple-diskimage');   // also tried 
> octet-stream
>  header('Content-Disposition: attachment; filename="My Cool Image.dmg"');
>  $size = filesize('/var/www/mypath/My Cool Image.dmg');
>  header('Content-Length: '.$size);
>  readfile('/var/www/mypath/My Cool Image.dmg');
>
> This same code works for a number of other file types that I serve: bin, zip, 
> pdf. Any suggestions? Professor Google is not my friend.
> --

Maybe file size limit somewhere?

--- End Message ---
--- Begin Message ---
On 4/25/12 10:54 PM, Brian Dunning wrote:
Hey all - I'm having no luck serving a .dmg from my online store. I stripped 
down the code to just the following to debug, but no matter what I get a 
zero-byte file served:

   header('Content-Type: application/x-apple-diskimage');   // also tried 
octet-stream
   header('Content-Disposition: attachment; filename="My Cool Image.dmg"');
   $size = filesize('/var/www/mypath/My Cool Image.dmg');
   header('Content-Length: '.$size);
   readfile('/var/www/mypath/My Cool Image.dmg');

This same code works for a number of other file types that I serve: bin, zip, 
pdf. Any suggestions? Professor Google is not my friend.

Most likely your file is larger than the memory you have available to PHP. The readfile() command will load the whole file into memory before streaming it out.

You'll want to use fopen, fread, fwrite, and fclose to loop through bytes in your file as you shuttle chunks to the client instead of slooping it all into memory in one hunk.

-- Dante

D. Dante Lorenso
da...@lorenso.com

--- End Message ---
--- Begin Message ---
On Wed, Apr 25, 2012 at 9:04 PM, Tommy Pham <tommy...@gmail.com> wrote:
> On Wed, Apr 25, 2012 at 8:54 PM, Brian Dunning <br...@briandunning.com> wrote:
>> Hey all - I'm having no luck serving a .dmg from my online store. I stripped 
>> down the code to just the following to debug, but no matter what I get a 
>> zero-byte file served:
>>
>>  header('Content-Type: application/x-apple-diskimage');   // also tried 
>> octet-stream
>>  header('Content-Disposition: attachment; filename="My Cool Image.dmg"');
>>  $size = filesize('/var/www/mypath/My Cool Image.dmg');
>>  header('Content-Length: '.$size);
>>  readfile('/var/www/mypath/My Cool Image.dmg');
>>
>> This same code works for a number of other file types that I serve: bin, 
>> zip, pdf. Any suggestions? Professor Google is not my friend.
>> --
>
> Maybe file size limit somewhere?

Forgot to mention that your code doesn't check the result [1].  If it
was this instead:

header('Content-Type: application/x-apple-diskimage');   // also tried
octet-stream
header('Content-Disposition: attachment; filename="My Cool Image.dmg"');
$size = filesize('/var/www/mypath/My Cool Image.dmg');
header('Content-Length: '.$size);
if (readfile('/var/www/mypath/My Cool Image.dmg') === false) die
('Error readfile ...');

Or alternatively, use xdebug in your dev environment. ;)

HTH,
Tommy

[1] http://php.net/readfile

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

Does anybody know what might influence the output of the date() function
besides date.timezone setting?

Running through some code in an app I'm working on, I have this code:

$timestamp = time();
$mysqlDatetime = date("Y-m-d G:i:s", $timestamp);

Logging these values yields:

INSERT TIMESTAMP:  1335414561
INSERT DATE TIME:  2012-04-26 4:29:21

But then from the interactive interpreter on the same box (same php.ini as
well):

php > echo date("Y-m-d G:i:s", 1335414561);
2012-04-25 22:29:21

I get this same output from another random computer of mine and I've
verified date.timezone is consistent in both environments.

Something's going on in the first case, but I'm unsure what; any ideas?

Your help appreciated as always.

-nathan

--- End Message ---
--- Begin Message ---
On 26/04/2012, at 4:40 PM, Nathan Nobbe wrote:

> Hi everyone,
> 
> Does anybody know what might influence the output of the date() function
> besides date.timezone setting?
> 
> Running through some code in an app I'm working on, I have this code:
> 
> $timestamp = time();
> $mysqlDatetime = date("Y-m-d G:i:s", $timestamp);
> 
> Logging these values yields:
> 
> INSERT TIMESTAMP:  1335414561
> INSERT DATE TIME:  2012-04-26 4:29:21
> 
> But then from the interactive interpreter on the same box (same php.ini as
> well):
> 
> php > echo date("Y-m-d G:i:s", 1335414561);
> 2012-04-25 22:29:21
> 
> I get this same output from another random computer of mine and I've
> verified date.timezone is consistent in both environments.
> 
> Something's going on in the first case, but I'm unsure what; any ideas?
> 
> Your help appreciated as always.
> 
> -nathan


A call to date_default_timezone_set() during execution can change the timezone. 
If you add echo date_default_timezone_get(); just before this, does it give the 
same output as your date.timezone setting?

---
Simon Welsh
Admin of http://simon.geek.nz/


--- End Message ---
--- Begin Message ---
On Wed, Apr 25, 2012 at 10:44 PM, Simon J Welsh <si...@welsh.co.nz> wrote:

> On 26/04/2012, at 4:40 PM, Nathan Nobbe wrote:
>
> > Hi everyone,
> >
> > Does anybody know what might influence the output of the date() function
> > besides date.timezone setting?
> >
> > Running through some code in an app I'm working on, I have this code:
> >
> > $timestamp = time();
> > $mysqlDatetime = date("Y-m-d G:i:s", $timestamp);
> >
> > Logging these values yields:
> >
> > INSERT TIMESTAMP:  1335414561
> > INSERT DATE TIME:  2012-04-26 4:29:21
> >
> > But then from the interactive interpreter on the same box (same php.ini
> as
> > well):
> >
> > php > echo date("Y-m-d G:i:s", 1335414561);
> > 2012-04-25 22:29:21
> >
> > I get this same output from another random computer of mine and I've
> > verified date.timezone is consistent in both environments.
> >
> > Something's going on in the first case, but I'm unsure what; any ideas?
> >
> > Your help appreciated as always.
> >
> > -nathan
>
>
> A call to date_default_timezone_set() during execution can change the
> timezone. If you add echo date_default_timezone_get(); just before this,
> does it give the same output as your date.timezone setting?
>

Simon,

I was dumping out the value from ini_get('date.timezone'); seems it must be
getting set at runtime.

Thanks!

-nathan

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

Nathan Nobbe <quickshif...@gmail.com> hat am 26. April 2012 um 06:40
geschrieben:
>
> INSERT TIMESTAMP:  1335414561
> INSERT DATE TIME:  2012-04-26 4:29:21
>
> But then from the interactive interpreter on the same box (same php.ini
as
> well):
>
> php > echo date("Y-m-d G:i:s", 1335414561);
> 2012-04-25 22:29:21
>
> I get this same output from another random computer of mine and I've
> verified date.timezone is consistent in both environments.
>

This definitly looks like a timezone offset!
Try the following code in your environments.

$date  = new  DateTime ( );
$tz  =  $date -> getTimezone ();
echo  $tz -> getName ();


PHP for CLI mode has a different php.ini than the one for apache2. Maybe
that is a problem?

Check also


php -i | grep "date.timezone"


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

this is more question than real problem (I hope :)). I include this
script into my pages to log IPs of visitors (they are saved info txt
file and send to e-mail later):

function getIPadress()
{
    if (isset($_SERVER["HTTP_CLIENT_IP"]))
    {
        return $_SERVER["HTTP_CLIENT_IP"];
    }
    elseif (isset($_SERVER["HTTP_X_FORWARDED_FOR"]))
    {
        return $_SERVER["HTTP_X_FORWARDED_FOR"];
    }
    elseif (isset($_SERVER["HTTP_X_FORWARDED"]))
    {
        return $_SERVER["HTTP_X_FORWARDED"];
    }
    elseif (isset($_SERVER["HTTP_FORWARDED_FOR"]))
    {
        return $_SERVER["HTTP_FORWARDED_FOR"];
    }
    elseif (isset($_SERVER["HTTP_FORWARDED"]))
    {
        return $_SERVER["HTTP_FORWARDED"];
    }
    else
    {
        return $_SERVER["REMOTE_ADDR"];
    }
}

// save log to txt
$fh = fopen($fileWithLog, 'a+') or die("Oups " . $fileWithLog ." !");
$IPAdress = getIPadress();
fwrite($fh, date('j.n.Y G:i:s') . $IPAdress . " (" .
gethostbyaddr($IPAdress) . ")\n");
fclose($fh);

...can this be some possible security risk (XSS or so..), becose I
does not check chars in IP adress and host name mainly. It is probably
crazy, but on the other side I think it isn't imposibble to use some
bad strings in host name.

Would you recommend use "$IPAdress = htmlspecialchars(getIPadress());"
or something like? Or is it nonsense?

Thx and excuse me, if this question is too stupid :(. Br, Mir R.

--- End Message ---

Reply via email to