English 中文(简体)
跟踪图像观点——PHP
原标题:Tracking image views - PHP

我很想能够告诉我,过去30天是否看到了一个形象仓,去除(加上与它相关的非行的数据)。 我知道,你能够以积极的方式读写和输出图像,但我听到了它对该系统的相当征税。 即便直接看待形象,我还是有办法追踪这些袭击? (能否获得?) 提前感谢。

最佳回答

您可以 par出吉大港山区保护区的标志,并在分析后进行。

尽管如此,我仍建议采用“动态PHP文档输出图像”方法,指出PHP档案只能输入档案。 是的,它比不通过购买力平价更慢,但它在你的系统上取得了很大的成绩。

问题回答

......

RewriteRule ^image/(.*)$ image.php?id=$1

以及PHP...

$id = $_GET["id"]; //don t forget to sanitize
mysql_query("UPDATE images SET views = views + 1 WHERE image =  $id "); //update no of views
header("Content-Type: image/jpeg"); //send image header
readfile($id); //output file to browser

你们可以制作一个画面,展示图像,绘制你的数据库,以显示对图像的看法。 通过确定贵国字母的返回类型:image/jpg 你们只能使用这一文字,而不是直接获取图像:

<?php
//simplified image display script

$imagepath="phpimages/$id.jpg";
$db->pingImage($id);
$image=imagecreatefromjpeg($imagepath);
header( Content-Type: image/jpeg );
imagejpeg($image);

?>

然后使用:

<img src= fetchimage.php?id=478  alt= tracked image  />

我知道,你需要为此建立一个数据库。

Sample schema:

Images
  id (int, PK)
  path (text)
  hits (int)

PHP:

// get_image.php
// note, this is just an example and I m not considering security or hacking attempts
$sql = mysql_query( SELECT * FROM images WHERE id =  .$_GET[ id ]);
$img

if(mysql_num_rows($img) == 1)
  while($row = mysql_fetch_assoc($sql))
    $img = $row;
else
  // handle some error

mysql_query("UPDATE images SET hit = hits + 1 WHERE id = ".$_GET[ id ]);
$img = file_get_contents($img[ path ]);
header( image/jpg );
echo $img;

这里可能出现错误,我只是给你一个一般性的想法。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签