Dynamically generated buttons and sessions
| From: | Olivier Guieu | Date: | Tue, 03 Oct 2000 09:25:53 +0000 |
| Subject: | Dynamically generated buttons and sessions | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-18391@lists.php.net to get a copy of this message | ||
Dear all,
I have just encountered a problem which is puzzling
me, I am using PHP4.0.1pl2 (compiled with ttf 1.3.1,
gd 1.8.3 into apache 1.3.12).
I was generating submit buttons on the fly using the
ttf/gd libraries. That worked fine until I enabled
automatic management of the sessions (I also
recompiled PHP using the enable-trans-sid flag). In
PHP.ini, I set the session.use_cookies and
session.auto_start to 1.
This works fine as long as cookies are enabled in my
browser (IE5.5 and Netscape Communicator 4.7). When I
set the cookies to disable or prompt, images can't be
displayed any longer.
The code I am using to display them is:
<INPUT TYPE="image" value="get" name="get"
SRC="/utils/button.php?s=20&text=Afficher"
ALT="Afficher" border="0" vspace=2>
where button.php is defined as:
<?
$BUTTONDIR="/images/dynamic/button/";
function createButton( $s, $filename, $text )
{
Header("Content-type:image/png");
$size=imagettfbbox($s,0,"../fonts/TIMES.ttf",$text);
$dx=abs($size[2]-$size[0]);
$dy=abs($size[5]-$size[3]);
$xpad=9;
$ypad=9;
$im=imagecreate($dx+$xpad,$dy+$ypad);
//$blue=ImageColorAllocate($im,0x2c,0x6D,0xAF);
$blue=ImageColorAllocate($im,176,196,222);
$black=ImageColorAllocate($im,0,0,0);
$white=ImageColorAllocate($im,255,255,255);
ImageRectangle($im,0,0,$dx+$xpad-1,$dy+$ypad-1,$black);
ImageRectangle($im,0,0,$dx+$xpad,$dy+$ypad,$white);
ImageTTFText($im,$s,0,(int)($xpad/2)+1,$dy+(int)($ypad/2),$black,"../fonts/TIMES.ttf",$text);
ImageTTFText($im,$s,0,(int)($xpad/2),$dy+(int)($ypad/2)-1,$white,"../fonts/TIMES.ttf",$text);
//ImageGif($im);
ImagePng($im,getenv("DOCUMENT_ROOT").$filename);
ImagePng($im);
ImageDestroy($im);
}
function readButton( $filename )
{
Header("Content-type:image/png");
$im =
ImageCreateFromPng(getenv("DOCUMENT_ROOT").$filename);
ImagePng($im);
ImageDestroy($im);
}
if(!isset($s))
$s=11;
$filename=$BUTTONDIR.$text."&s=".$s.".png";
if ( File_exists(getenv("DOCUMENT_ROOT").$filename) )
readButton( $filename );
else
createButton( $s, $filename, $text );
?>
Is there any way to work around this?
Thanks a lot.
Cheers,
Olivier Guieu.
__________________________________________________
Do You Yahoo!?
Yahoo! Photos - 35mm Quality Prints, Now Get 15 Free!
http://photos.yahoo.com/