// veppel.net //

ie6 - cache-control und nicht gefundene daten

meine erkenntnis des tages:

manchmal will man per php files dem besucher nur unter gewissen bedingungen zur verfügung stellen. z.b. wenn ich ein file
/home/myaccount/test.pdf aufs internet stellen will, ohne es im http-baum zu platzieren. z.b. so:

$file = '/home/myaccount/test.pdf';

$f = fopen($file, 'r');

$data = fread($f,filesize($file);

und um es nun auszugeben, gibt man paar headers mit:

header('Content-Disposition: attachment; filename="test.pdf"');

header("Content-type: application/pdf";);

echo $data;

aber damit kanns ein ganz dolles problem geben. und zwar liefert php offensichtlich standardmässig als cache-control zeug wie no-cache mit. und wenn jemand ein eben solches file öffnen und in einem externen viewer anschauen will (z.b. acrobat), dann geht das mit firefox prima. bei IE kriegt man nur gemecker von wegen: no valid file found oder ähnlich.

offensichtlich speichert der IE das angewählte file nicht im cache, öffnet aber die helper application mit dem pfad für ein file im cache.

dem verhalten kann natürlich einfach einhalt geboten werden, indem man selbst die kontrolle über das caching übernimmt. einfach bei den header ausgaben noch folgende zeile einfügen:

header("Cache-Control: public, max-age=600, must-revalidate");

damit wird das file für 600 sekunden gecacht und kann von der helper application geöffnet werden ...

php variablen vergleich

hab da was lustiges gefunden.

bei einem nicht typensicheren vergleich zwischen nem string 'first' und der integer zahl 1 gibts ein true zurück. d.h. sowas wie

$c = 1;
$d = 'first';
if($c == $d) {
  // gibt true
}
if($c === $d) {
  // gibt falsch
}

How to install pdflib in combination with php 4.3.X

There are two problems: php does not compile with pdflib support and pear wrapper does not compile out of the box either.

­

i wrote this page for me, just to remember the difficulties when i tried to install PDFLIB, but maybe it will also be helpful to somebody. It's just the usual RTFM problem, if you read the documentation which comes with pdflib (pdflib lite), you can get it working in a few minutes...

This instructions just apply to debian woody with apache 1.3.33 and php 4.3.10 (compiled by yourself).

There are two problems:

1) PDFLIB >= 6 does not work with php. Compiling of php failes when the --with-pdflib flag is set. bugs.php.net/bug.php?id=29297

2) GD: pecl can not compile the wrapper as php currently does not support to compile pecl packages which use the gd library. If you try it anyway (pecl install pdflib), you will get something like this:

running: make

/bin/sh /var/tmp/pear-build-root/pdflib-2.0.4/libtool --mode=compile gcc -I.
-I/tmp/tmpnQxKT7/pdflib-2.0.4 -DPHP_ATOM_INC
-I/var/tmp/pear-build-root/pdflib-2.0.4/include
-I/var/tmp/pear-build-root/pdflib-2.0.4/main
-I/tmp/tmpnQxKT7/pdflib-2.0.4
-I/usr/local/include/php
-I/usr/local/include/php/main
-I/usr/local/include/php/Zend
-I/usr/local/include/php/TSRM
-I/opt/pdflib/6.0.1/include
-DHAVE_CONFIG_H -g
-O2 -prefer-pic
-c /tmp/tmpnQxKT7/pdflib-2.0.4/pdf.c
-o pdf.lo

gcc -I. -I/tmp/tmpnQxKT7/pdflib-2.0.4 -DPHP_ATOM_INC
-I/var/tmp/pear-build-root/pdflib-2.0.4/include
-I/var/tmp/pear-build-root/pdflib-2.0.4/main
-I/tmp/tmpnQxKT7/pdflib-2.0.4
-I/usr/local/include/php
-I/usr/local/include/php/main
-I/usr/local/include/php/Zend
-I/usr/local/include/php/TSRM
-I/opt/pdflib/6.0.1/include
-DHAVE_CONFIG_H -g -O2 -c

/tmp/tmpnQxKT7/pdflib-2.0.4/pdf.c -fPIC -DPIC -o pdf.lo

/tmp/tmpnQxKT7/pdflib-2.0.4/pdf.c:91: ext/gd/php_gd.h: No such file or directory

/tmp/tmpnQxKT7/pdflib-2.0.4/pdf.c:93: ext/gd/libgd/gd.h: No such file or directory

make: *** [pdf.lo] Error 1

`make' failed

I assume you have a working php/apache enviroment.

1. Download the pdflib-lite from www.pdflib.com/products/pdflib/download-source.html, compile it with --enable-php flag and install it.

2. Get the latest php version, run ./configure with your settings (if you don't remember them, just run phpinfo() ...), compile and install ...

3. Now, the thing is that you can't diretly use the ./configure --with-pdflib flag to use the pdflib within php. But, you can use a pecl wrapper: pear install pdflib. This should download the pdflib wrapper module, compile it and install it. But it will fail (usually).The problem is, that pear install can't compile modules which use the gd library, but just because some files are missing. All you need is to symlink the php-4.3.10/ext/gd directory to PREFIX/include/php/ext/gd (or copy it ...) See also: www.pdflib.com/products/pdflib/info/PDFlib-in-PHP-HowTo.pdf