Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/254.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess重写规则在加载图像时执行php脚本_Php_.htaccess_Laravel_Mod Rewrite - Fatal编程技术网

.htaccess重写规则在加载图像时执行php脚本

.htaccess重写规则在加载图像时执行php脚本,php,.htaccess,laravel,mod-rewrite,Php,.htaccess,Laravel,Mod Rewrite,所以我一直在致力于在一个laravel项目中创建一个webbug,每当加载任何图像时,它都会记录基本信息。然而,我的.htaccess文档似乎无法正确识别我的扩展,因为它没有执行我的脚本。我知道当我运行脚本时,数据库会得到新的输入。脚本本身没有被调用。我使用刀片模板创建在路由资源上执行的视图,或者在本例中用于测试特定路由 routes.php Route::resource('identifyVerification', 'PhishingController'); Route::get('/b

所以我一直在致力于在一个laravel项目中创建一个webbug,每当加载任何图像时,它都会记录基本信息。然而,我的.htaccess文档似乎无法正确识别我的扩展,因为它没有执行我的脚本。我知道当我运行脚本时,数据库会得到新的输入。脚本本身没有被调用。我使用刀片模板创建在路由资源上执行的视图,或者在本例中用于测试特定路由

routes.php

Route::resource('identifyVerification', 'PhishingController');
Route::get('/breachReset','PhishingController@breachReset');
Route::get('/breachReset/verifyUser', 'PhishingController@breachVerify');

Route::get('/path/to/sec_question.png','PhishingController@imageReturnTest');
<?php

$db = new mysqli('host', 'username', 'password', 'database');

if (mysqli_connect_errno()) {
echo 'Error: Could not connect to the database..';
exit;
}

$ip = $_SERVER['REMOTE_ADDR'];
$host = gethostbyaddr($_SERVER['REMOTE_ADDR']);
$reqpath = $_SERVER['REQUEST_URI'];
$browseragent = $_SERVER['HTTP_USER_AGENT'];
$date = date("Y-m-d");
$time = date("H:i:s");
print "vars created";
$sql = "INSERT INTO database.table (id,ip,host,
   browser_agent,req_path,access_date,access_time) VALUES 
   (null,'$ip','$host','$browseragent','$reqpath','$date',
   '$time');";
print "sql executed";
$result = $db->query($sql);

$result->free();
$db->close();

header( 'Content-type: image/jpg' );
?>
我使用的测试路径是最后一条,@imageReturnTest。它引用了PhishingController中定义如下的函数。它正在打开我的公共目录中的img目录中的测试映像

public function imageReturnTest() {
        $path = './img/sec_question.png';
        $fp = fopen($path,'rb');
        header('Content-Type: image/png');
        header('Content-Length: ' . filesize($path));
        fpassthru($fp);
        exit;
    }
加载此图像时,my.htaccess文件将看到加载了扩展名为.png的图像,然后运行重定向以执行webbug_test.php页面。下面是我在laravel中的.htaccess文件。我的规则不仅应该在PNG上执行,还应该在任何图像上执行(JPEG、PNG、GIF等,可以根据需要添加扩展名)。正如你们所看到的,我尝试了通过StackOverflow和其他描述如何设置透明Webbug的网站找到的解决方案。两个都没用

.htaccess

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # My new rule to execute webbug
    RewriteRule ^(.*).(png|jpg|gif)$ webbug_test.php

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

</IfModule>
下面是我的webbug_test.php脚本,应该通过.htaccess调用它。正如我所说的,我可以通过IDE测试仪运行这个页面,它将运行它的SQL执行,并将适当的信息插入数据库中,以供即兴执行。但是,在加载图像时不会调用它

webbug\u test.php

Route::resource('identifyVerification', 'PhishingController');
Route::get('/breachReset','PhishingController@breachReset');
Route::get('/breachReset/verifyUser', 'PhishingController@breachVerify');

Route::get('/path/to/sec_question.png','PhishingController@imageReturnTest');
<?php

$db = new mysqli('host', 'username', 'password', 'database');

if (mysqli_connect_errno()) {
echo 'Error: Could not connect to the database..';
exit;
}

$ip = $_SERVER['REMOTE_ADDR'];
$host = gethostbyaddr($_SERVER['REMOTE_ADDR']);
$reqpath = $_SERVER['REQUEST_URI'];
$browseragent = $_SERVER['HTTP_USER_AGENT'];
$date = date("Y-m-d");
$time = date("H:i:s");
print "vars created";
$sql = "INSERT INTO database.table (id,ip,host,
   browser_agent,req_path,access_date,access_time) VALUES 
   (null,'$ip','$host','$browseragent','$reqpath','$date',
   '$time');";
print "sql executed";
$result = $db->query($sql);

$result->free();
$db->close();

header( 'Content-type: image/jpg' );
?>

您可以创建一个动态php文件,用于提供图像并将其他详细信息记录到数据库中。
例子

并从image.php记录数据。

它是否需要实际传递图像才能工作,或者是否可以作为透明的webbug运行?我想我以前尝试过这个,但它给我带来了问题,然而,我可能没有正确地实现它。您只需要传递图像名称,然后使用$\u get在php文件中获取该名称。它应该会起作用。