为网站设置 phpThumb,我想通过对每个图像使用 hash-url 来保护脚本。
我已在 phpThumb.config.php
中启用安全选项:
// * Security configuration
$PHPTHUMB_CONFIG['high_security_enabled'] = true; // if enabled, requires 'high_security_password' set to be set and requires the use of phpThumbURL() function (at the bottom of phpThumb.config.php) to generate hashed URLs
$PHPTHUMB_CONFIG['high_security_password'] = ' '; // required if 'high_security_enabled' is true, and must be at complex (uppercase, lowercase, numbers, punctuation, etc -- punctuation is strongest, lowercase is weakest; see PasswordStrength() in phpThumb.php). You can use a password generator like http://silisoftware.com/tools/password-random.php to generate a strong password
我按照文档中的描述使用函数 phpThumbURL() ;
require_once('img/phpThumb.config.php');
echo '<img src="'.phpThumbURL('src=/wp-content/uploads/2011/08/wall140-73.jpg&w=640&h=400&zc=1').'">';
不过,我得到的只是错误:无效的哈希值
我让 phpThumbs 在没有这个安全选项的情况下工作,但我真的不想让任何人打开脚本在我的服务器上生成缩略图。
我不明白哈希值如何无效,以及为什么它不起作用。
最佳答案
对我来说,phpThumb.config.php底部的信息提供了帮助
//////////////////////////////////////////////////////////////////////////////
// Function for generating hashed calls to phpThumb if 'high_security_enabled'
// example:
// require_once('phpThumb/phpThumb.config.php');
// echo '<img src="'.htmlspecialchars(phpThumbURL('src=/images/pic.jpg&w=50', '/phpThumb/phpThumb.php')).'">';
所以为了制作拇指,我使用函数htmlspecialchars(phpThumbURL(...)):
$path = 'C:\wamp\www\_img_test\\'; // YOUR PATH
require_once($path.'phpThumb\phpThumb.config.php');
$img = '1.jpg'; // YOUR IMAGE
$ParameterString = 'w=200&h=200'; // YOUR PARAMS
$url = 'http://localhost/_img_test/'; // YOUR URL
$path = htmlspecialchars(phpThumbURL('src=../'.$img.'&'.$ParameterString, $url.'phpThumb/phpThumb.php'));
echo '<img src="'.$path.'">'; // YOUR IMAGE
echo $path; // // YOUR IMAGE PATH
当然是在phpThumb.config.php中设置:
$PHPTHUMB_CONFIG['high_security_enabled'] = true;
$PHPTHUMB_CONFIG['high_security_password'] = 'V_8r}ZZj-)p4vVx0H6.4'; // YOUR PASSWD from: http://silisoftware.com/tools/password-random.php
$PHPTHUMB_CONFIG['disable_debug'] = true;
对我来说它有效。
关于phpThumb - 无效的哈希值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7053432/