HTTPS üzerinden Google Charts

3 Cevap php

Ben güvenli bir site görüntü olarak grafikler yüklemeye çalışıyorum. Https üzerinden Google Chart görüntüsünün bir örnek bu olurdu:

http://www.google.com/chart?cht=lc&chs=200x125&chd=s:helloWorld

Sorun doğrudan bağlantıya tıklayarak bu gibi bir görüntü yükleyebilirsiniz ederken, sayfanızda bir görüntü olarak dahil edemezler. Bu sadece yük olmayacak.

Bu nasıl bypass üzerinde herhangi bir fikir? Veya çözümü genellikle PHP kullanarak?

3 Cevap

Google HTTPS üzerinden Grafikler desteklemiyor ...

Ben aynı problem vardı.

http://groups.google.com/group/google-chart-api/browse_thread/thread/95c463d88cf3cfe4

Sen could Ancak böyle bir sorunu çözmek için bir HTTPS bağlantısı üzerinden google HTTP bağlantı filtrelemek için bir proxy sayfa oluşturmak için PHP veya. Net kullanabilirsiniz.

İşte ben kullandım basit bir PHP proxy ...

<?php
    // PHP Proxy
    // Loads a XML from any location. Used with Flash/Flex apps to bypass security restrictions
    // Author: Paulo Fierro
    // January 29, 2006
    // usage: proxy.php?url=http://mysite.com/myxml.xml

    $session = curl_init($_GET['url']);                    // Open the Curl session
    curl_setopt($session, CURLOPT_HEADER, false);          // Don't return HTTP headers
    curl_setopt($session, CURLOPT_RETURNTRANSFER, true);   // Do return the contents of the call
    $xml = curl_exec($session);                            // Make the call
    header("Content-Type: text/xml");                  // Set the content type appropriately
    echo $xml;        // Spit out the xml
    curl_close($session); // And close the session
?>

Google nihayet HTTPS izin kendi API güncellenmiş gibi görünüyor. Yapmanız gereken tüm temel URL https://chart.googleapis.com/chart gibi bir şey olduğunu ve gayet iyi çalışıyor, böylece chart.googleapis.com için hostname geçiş olduğunu. Tadını çıkarın!

Başlık seti: google Referrer sahip grafikler için https isteklerini engelliyor gibi görünüyor.

[tla ~]$ curl 'http://www.google.com/chart?cht=lc&chs=200x125&chd=s:helloWorld' 2>/dev/null | file -
/dev/stdin: PNG image, 200 x 125, 8-bit/color RGB, non-interlaced
[tla ~]$ curl 'https://www.google.com/chart?cht=lc&chs=200x125&chd=s:helloWorld' 2>/dev/null | file -
/dev/stdin: PNG image, 200 x 125, 8-bit/color RGB, non-interlaced
[tla ~]$ curl -H 'Referer: http://stackoverflow.com' 'http://www.google.com/chart?cht=lc&chs=200x125&chd=s:helloWorld' 2>/dev/null | file -
/dev/stdin: PNG image, 200 x 125, 8-bit/color RGB, non-interlaced
[tla ~]$ curl -H 'Referer: http://stackoverflow.com' 'https://www.google.com/chart?cht=lc&chs=200x125&chd=s:helloWorld' 2>/dev/null | file -
/dev/stdin: ASCII HTML document text, with very long lines