【发布时间】:2016-12-20 20:39:17
【问题描述】:
我搜索了 Google 和 Stackoverflow,但找不到答案。可能是因为我正在寻找错误的问题。没有正确的问题,就很难得到正确的答案。所以我希望有人可以帮助我。
我创建了一个前 20 名列表,人们可以在其中对他们最喜欢的网站进行排名(我知道这不是原创,但我这样做是为了学习 php)
可以将网站添加到数据库并根据投票进行排序。每个网站在数据库中都有自己唯一的 ID、名称和位置。
我不知道如何执行以下操作。
在显示的列表旁边显示一个获取代码按钮。此按钮将为可在任何网站上显示的图像文件创建代码。例如:
<img src="http://www.example.com/counter.php?id=47"/>
甚至更好
<img src="http://www.example.com/47.gif"/>
为此,我需要编写一个 php 代码,该代码可以获取 id 并将其转换为漂亮的图像文件,但我被卡住了。我已经看到 twitter、feedburner、Technorati 和 100 多个其他网站这样做,但我不知道如何。
我发现了这个伪造 feedburner 的代码,但我不知道如何将它变成我需要的。
<?php
//Send a generated image to the browser
create_image();
exit();
function create_image(){
//Create the image resource
$image = imagecreatefromgif('image.gif');
//Create text color
$brown = ImageColorAllocate($image, 0, 0, 0);
//Check for the get parameters
if (isset($_GET['count']) && is_numeric($_GET['count']))
$rank = $_GET['count'];
else
$rank = 20;
// Some Alignment Calculations
$bbox = imagettfbbox(8.5, 1,'verdana.ttf', $rank);
$xcorr = 0 + $bbox[2]; $xcorr = 31 - $xcorr;
//Add the number in brown color to the image
imagettftext($image,8.5,0,$xcorr,16,$brown,'verdana.ttf',$rank);
//Tell the browser what kind of file is come in
header("Content-Type: image/gif");
imagegif($image);
//Free up resources
ImageDestroy($image);}?>
基于 www.mygeekpal.com/how-to-fake-your-feedburner-subscribers/
使用上面的代码并将其命名为 counter.php 我可以从数据库中获取位置并创建
<img src='http://www.example.com/counter.php?count=".$array ['position']."' />
这会从数据库中获取一个网站的位置($array 已经被提取)并创建一个位置为 nr 的图像。
工作正常,但一旦位置根据用户评分发生变化,图像将不会显示正确的数据。
我希望有人可以提供帮助。谢谢。
夏天
基本上,我想做的是根据网站的排名显示最新数据。就像显示 Twitter 关注者的数量一样,例如 http://twittercounter.com/counter/?username=labnol 或 http://feeds.feedburner.com/~fc/labnol 上的 feedburner 关注者 两者都是根据数据库中的信息显示数字的图像。但我想根据网站在数据库中的排名创建自己的图像。
【问题讨论】: