当我将谷歌分析添加到我的网站时,它现在不会加载图像

时间:2014-07-27 03:16:51

标签: php html google-analytics

以下是图片的代码

我正在使用Joomla和Jumi - 我之前遇到过与jumi有预定义项目的问题,并想知道它是否与此有关?

  <?php

include("settings.php");

    mysql_connect($loginURL,$username,$password);
    @mysql_select_db($database) or die("-9");

  $cardUUID = $_GET['id'];
  $sql = "SELECT * FROM card WHERE UUID='{$cardUUID}'";
  $result = mysql_query("$sql");
  if (!$result) {  
  echo 'Could not run result query: ' . mysql_error();    echo $sql; exit;  }

  $row = mysql_fetch_assoc($result);

  header("Content-type: image/jpg");
   if(base64_decode($row['cardimage']) == false)
        echo $row['cardimage'];
    else
        echo base64_decode($row['cardimage']); 


?>

这是我添加的GA代码

<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-243-1', 'auto');
  ga('send', 'pageview');

</script>

1 个答案:

答案 0 :(得分:1)

主要问题是当你使用base64decode时。

您需要使用echo base64_decode($row['cardimage']);

更改此file_get_contents($row['cardimage']);

Online demo

这里是代码

<?php
//In this example I am going to use hard code cardimage data
$row['cardimage'] = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAR4AAAAvCAMAAAACRlVYAAAABGdBTUEAALGPC/xhBQAAAGBQTFRFVj18Vj21Vj3NVpHeVrbqnz18nz21nz3Nn5Hen872vz18vz3Nv+D/1JF81JHN1PL/5LZ85La15M7e5P//9M619M7e9ODq9PL29PL/9P///+DN/+De//Le///q///2////FMkDhgAAA4BJREFUaIHtmOt62jAMhtMtbIOF4Q1vXT0g93+Xja2DJceBpMDK00ffjwbXjiS/PshO05hMJpPJZDKZTCaTyfQA+vzSR7npFl2sP6wqNU+7HnXcNE17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iWHAAAAAElFTkSuQmCC";

header("Content-type: image/png");
if(base64_decode($row['cardimage']) == false)
    echo $row['cardimage'];
else
    echo file_get_contents($row['cardimage']); 
?>