dongxin1999 2014-05-02 15:50
浏览 43

没有在Codeigniter中进行身份验证的图像

I'm building a web application with Codeigniter. I have some images on my server and I want that only logged users can see them. The login is made with the session class of codeigniter.

I don't want that external users can open the image

http://www.mywebapp.com/images/privateimage.jpg

Opening this image I have to control if there is a valid codeigniter session and then give the image.

I've tried to made a controller called "images" and I've tried to add a rule in the htaccess file in order to call a function that checks the session and than sends the image to the client, but this

RewriteRule ^images/(.*)$ index.php?/images/$1 [L]

doesn't work. I don't know very well the rules of the htaccess files and I don't know if there are simplier ways to do this, but I want to preserve the correspondence between the url of the image and its position on the web server if it's possible.

Thank you

  • 写回答

1条回答 默认 最新

  • dongyang1518 2014-05-05 11:19
    关注

    Proof Of Concept

    First Step. Put the images folder outside the webserver folder, with this nobody can see the images.

    Second Step. Create a controler:

    <?php
    class Viewer extends CI_Controller {
    public function __construct() {
        parent::__construct();
        //here you can check if the user has a session if not die!! XD
    
    
    }
    
    public function index() {
        //nothing here o blank page
    } 
    
    
    public function see_pic($name) {
        header ("Content-type: image/jpeg");
        $ruta = "/folder/with/pics/".$name; 
        $im = imagecreatefromJPEG($ruta);
        @ImageJPEG($im);
            @ImageDestroy($im);
    }
    
    ?>
    

    And then when you put the image "http://my_server.com/viewer/see_pic/my_dog.jpg"

    评论

报告相同问题?

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题