PHP Classes

IE problems - cache and SSL functionality

Recommend this page to a friend!

      Google Graph  >  All threads  >  IE problems - cache and SSL...  >  (Un) Subscribe thread alerts  
Subject:IE problems - cache and SSL...
Summary:Added cache functionality for SSL connections
Messages:3
Author:Martin Stub
Date:2010-03-23 11:04:33
Update:2010-03-23 11:07:48
 

  1. IE problems - cache and SSL...   Reply   Report abuse  
Picture of Martin Stub Martin Stub - 2010-03-23 11:04:33
Great class.

I have made 1 minor change and added 1 cache functionality to make the graphs work with Internet Explorer. The graphs worked perfectly in Firefox, Chrome and Safari.

In IE the graphs would not show and it turned out that it was the & (ampersand) in the url. Made a str_replace just before the $url is returned to replace & with &
$url = str_replace ("&", "&", $url);

For SSL connections the graphs would not show in IE. This was weird. I ended up using a cache function which solved the issue.

In GoogleGraph.php I changed this
var $BASE_ADDRESS = "http://chart.apis.google.com/chart?";
to
var $BASE_ADDRESS = "chartCache.php?";

The content of file chartChache.php:

define ('CACHEFOLDER', '../chartcache/'); // I place this folder outside the root directory for added security - remember to chmod for write access
$url = $_SERVER['REQUEST_URI'];
$parts = parse_url ($url);
$query = $parts['query'];
$md5 = md5 ($query);
$image = @file_get_contents (CACHEFOLDER.$md5.'.png');
if (!$image) {
$image = file_get_contents ("https://www.google.com/chart?".$query);
$image = file_get_contents ("https://www.google.com/chart?".$query);
$handle = fopen (CACHEFOLDER.$md5.'.png', "w");
fwrite ($handle, $image);
fclose ($handle);
}
header ("Content-Type: image/png");
echo $image;

Hope this helps somebody.

Best regards
stubben

  2. Re: IE problems - cache and SSL...   Reply   Report abuse  
Picture of Martin Stub Martin Stub - 2010-03-23 11:07:48 - In reply to message 2 from Martin Stub
So I cannot handle tab and space on the keyboard... I apologize :-)

I wanted to give an example of another google url.

Instead of
$image = file_get_contents ("https://www.google.com/chart?".$query);
then you could use this, if you don't need or want SSL connection to google.
$image = file_get_contents ("http://chart.apis.google.com/chart?".$query);

No matter what, that line is only suppose to be written once!

Sorry for the confusion.

Best Regards
stubben

  3. Re: IE problems - cache and SSL...   Reply   Report abuse  
Picture of Martin Stub Martin Stub - 2010-03-23 11:04:35
Great class.

I have made 1 minor change and added 1 cache functionality to make the graphs work with Internet Explorer. The graphs worked perfectly in Firefox, Chrome and Safari.

In IE the graphs would not show and it turned out that it was the & (ampersand) in the url. Made a str_replace just before the $url is returned to replace & with &
$url = str_replace ("&", "&", $url);

For SSL connections the graphs would not show in IE. This was weird. I ended up using a cache function which solved the issue.

In GoogleGraph.php I changed this
var $BASE_ADDRESS = "http://chart.apis.google.com/chart?";
to
var $BASE_ADDRESS = "chartCache.php?";

The content of file chartChache.php:

define ('CACHEFOLDER', '../chartcache/'); // I place this folder outside the root directory for added security - remember to chmod for write access
$url = $_SERVER['REQUEST_URI'];
$parts = parse_url ($url);
$query = $parts['query'];
$md5 = md5 ($query);
$image = @file_get_contents (CACHEFOLDER.$md5.'.png');
if (!$image) {
$image = file_get_contents ("https://www.google.com/chart?".$query);
$image = file_get_contents ("https://www.google.com/chart?".$query);
$handle = fopen (CACHEFOLDER.$md5.'.png', "w");
fwrite ($handle, $image);
fclose ($handle);
}
header ("Content-Type: image/png");
echo $image;

Hope this helps somebody.

Best regards
stubben