保护创建映像的PHP代码 [英] Securing PHP Code that Creates Images

查看:59
本文介绍了保护创建映像的PHP代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常好的php网站,这也是相当安全的。

但是,我写了一些PHP代码来创建一些动态图像基于

数据库数据,但是我不知道如何保护这个脚本?

当我通过img src =" myimage.php引用php代码时,没有我的

会话变量可在脚本中使用。所以,如果没有我的

会话变量,我怎么想确保脚本只是由有效用户运行,而不是只能盲目输入

随机参数到我的图像创建脚本?

我真的很难过这个。

I have a pretty nice php web site, that''s also reasonably secure.
However, I wrote some php code to create some dynamic images based on
database data, but I can''t figure out how to secure this script?
when I reference the php code via img src="myimage.php", none of my
session variables are available for use in the script. So, without my
session variables, how am I suppose to ensure that the script is only
run by a valid user, rather than just anyone who can blindly type in
random parameters to my image creation script?
I''m really stumped on this one.

推荐答案

Steve写道:
Steve wrote:
我有一个非常好的php网站,这也是相当安全的。
但是,我写了一些PHP代码来创建一些基于数据库数据的动态图像,但我无法弄清楚如何保护这个脚本?

当我通过img src =" myimage.php"引用php代码时,我的
会话变量都不能在脚本中使用。因此,如果没有我的会话变量,我想如何确保脚本仅由有效用户运行,而不是只能盲目输入
随机参数到我的图像的任何人创作脚本?

我真的很难过这个。
I have a pretty nice php web site, that''s also reasonably secure.
However, I wrote some php code to create some dynamic images based on
database data, but I can''t figure out how to secure this script?

when I reference the php code via img src="myimage.php", none of my
session variables are available for use in the script. So, without my
session variables, how am I suppose to ensure that the script is only
run by a valid user, rather than just anyone who can blindly type in
random parameters to my image creation script?

I''m really stumped on this one.




不确定为什么会遇到会话问题,无论如何

它不是一个完美的解决方案,因为如果他们没有启用
cookies就不会工作。

我在其中一个网站遇到了类似的问题,而且由于人们链接到生成的图片而加上了b
$ b服务器
我们最近发布了一个完全修改过的版本的网站,带有新的

设计,我重写了生成图像的引擎。现在不是通过像foo.php这样生成图像来生成图像?param1 = x& param2 = y

类型的东西,我们生成所有图像,而页面是正在创建

,其中基本上是随机图像名称(它们是用于保存图像的

数据的md5哈希值)。


然后将图像保存到文件系统并链接到页面中,例如

637b9aa7da08f0c649367a39f9d5023a.jpg每小时一次脚本在

服务器上运行它删除了比两小时前生成的更多这些临时图像的更多

。 (如果在页面上再次请求图像并且文件

存在,则时间戳更新为当前时间。)


这样做的好处这种方式是人们无法直接访问

图像生成脚本,并且没有可能从另一个网站链接到

图像,因为他们会得到2小时后破损的图像。

唯一的缺点我可以看到,如果浏览器返回一个缓存的页面

a几个小时之后它们可能最终会出现一些损坏的图像,但这看起来是

在浏览服务器日志时非常罕见。


此解决方案可能对您有用,也可能对您有用,具体取决于各种各样的

因素。如果您想要更多信息,请随时给我发电子邮件 - 只需在我的电子邮件地址更改

blackhole for chris。


-

Chris Hope - 电动工具箱 - http://www.electrictoolbox.com/


Chris Hope< bl ******* @ electrictoolbox.com>在消息新闻中写道:< 7o ******************** @ news.xtra.co.nz> ...
Chris Hope <bl*******@electrictoolbox.com> wrote in message news:<7o********************@news.xtra.co.nz>...
史蒂夫写道:
< snip>
Steve wrote: <snip>
当我通过img src =" myimage.php"引用php代码时,我的
会话都没有变量可以在脚本中使用。
when I reference the php code via img src="myimage.php", none of my
session variables are available for use in the script.




除非您的脚本有问题,否则不应该发生。

Not确定你为什么会遇到会话问题,无论如何
它不是一个完美的解决方案,因为如果他们没有启用cookie就不会工作。


不确定,你在说什么。


< snip>这样做的好处是人们无法直接访问图像生成脚本,并且没有可能从另一个站点链接到
图像,因为他们会得到一个破碎的图像2小时后。



It shouldn''t happen unless your script is buggy.
Not sure why you would be having problems with the session stuff, and anyway
it''s not a perfect solution because it won''t work if they don''t have
cookies enabled.
Not sure, what are you talking about.

<snip> The advantage of doing it this way is that people cannot directly access the
image generation script, and there''s no possibilty of hotlinking to the
image from another site as they''ll get a broken image after 2 hours.




顺便提一下,可以通过会话和

输出缓冲技术轻松修复热链接。


-

|只是另一个PHP圣人|

电子邮件:rrjanbiah-at-Y!com



Incidentally, hotlinking can be *easily* fixed with session and
output buffering techniques.

--
| Just another PHP saint |
Email: rrjanbiah-at-Y!com


R. Rajesh Jeba Anbiah写道:
R. Rajesh Jeba Anbiah wrote:
Chris Hope< bl ******* @ electrictoolbox.com>在消息中写道
新闻:< 7o ******************** @ news.xtra.co.nz> ...
Chris Hope <bl*******@electrictoolbox.com> wrote in message
news:<7o********************@news.xtra.co.nz>...
史蒂夫写道:


< snip>


<snip>

>当我通过img src =" myimage.php"引用php代码时,没有我的
>会话变量可以在脚本中使用。
> when I reference the php code via img src="myimage.php", none of my
> session variables are available for use in the script.



除非您的脚本有问题,否则不应该发生。



It shouldn''t happen unless your script is buggy.

不知道为什么你会遇到会话问题,而且无论如何它不是一个完美的解决方案,因为如果他们没有启用cookie就不会工作。
Not sure why you would be having problems with the session stuff, and
anyway it''s not a perfect solution because it won''t work if they don''t
have cookies enabled.



不确定,你在说什么。

< snip>



Not sure, what are you talking about.

<snip>

这样做的好处是人们不能直接访问图像生成脚本,并且没有可能将来自其他网站的图像链接到图像,因为他们将在2小时后获得损坏的图像。
The advantage of doing it this way is that people cannot directly access
the image generation script, and there''s no possibilty of hotlinking to
the image from another site as they''ll get a broken image after 2 hours.


顺便说一下,可以通过会话和输出缓冲技术轻松*修复热链接。



Incidentally, hotlinking can be *easily* fixed with session and
output buffering techniques.




除了你不能依赖会话。如果他们的浏览器没有启用cookie,那么每个请求都会出现在新会话中。


-

Chris Hope - 电动工具箱 - http://www.electrictoolbox.com/


这篇关于保护创建映像的PHP代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆