html yardımcı bağlantı yöntemi kullanılarak cakephp güvenli bağlantı

3 Cevap php

What's the best way in cakephp to extend the html->link function so that I can tell it to output a secure(https) link? Right now, I've added my own secure_link function to app_helpers that's basically a copy of the link function but adding a https to the beginning. But it seems like there should be a better way of overriding the html->link method so that I can specify a secure option.

http://groups.google.com/group/cake-php/browse%5Fthread/thread/e801b31cd3db809a I also started a thread on the google groups and someone suggested doing something like

$html->link('my account', array('base' => 'https://', 'controller' => 'users'));

ama o çalışma alamadım.

Sadece eklemek için, bu ben yukarıdaki kodu olduğunda çıkışı budur.

<a href="/users/index/base:https:/">my account</a>

I think there's a bug in the cake/libs/router.php on line 850. There's a keyword 'bare' and I think it should be 'base' Though changing it to base doesn't seem to fix it. From what I gather, it's telling it to exclude those keys that are passed in so that they don't get included as parameters. But I'm puzzled as to why it's a 'bare' keyword and the only reason I can come up with is that it's a type.

3 Cevap

Sadece bir sayfanın güvenli bir sürüme bağlantı tamamen güvenli olmayan sürümüne erişimi engellemez, bu nedenle daha iyi bir yaklaşım gerekli eylemler için geçiş otomatik https uygulamak olabilir.

<?php
class UsersController extends AppController {

    var $components = array('Security');

    function beforeFilter() {
        $this->Security->blackHoleCallback = '_forceSecure';
        $this->Security->requireSecure();
        /**
         * It is very common to require invocation 
         * of the parent beforeFilter().
         * Your usage may have the invocation 
         * at the top instead of at the bottom.
         */
        parent::beforeFilter();
    }

    function _forceSecure() {
        $this->redirect( 'https://'.env('SERVER_NAME').env('REQUEST_URI') );
    }
}
?>

Eğer kontrolörleri / eylemler https:// her linke prepending konusunda endişelenmenize gerek kalmadan güvenli gerek seçebilirsiniz Bu tekniği kullanarak.

_forceSecure (), Daha iyi yönlendirmek için bu hattı kullanmak olacaktır:

$this->redirect('https://'.env('SERVER_NAME').env('REQUEST_URI'));

Aksi takdirde bir GET isteğinde belirtilen herhangi bir parametre kaybedersiniz.

Eğer tabanını geçersiz kılmak istiyorsanız, sunucu adını protokol sadece belirtmek zorunda.

Oluşturmak istediğiniz bağlantı olmalıdır Eğer https://example.com/mysite/users/action ardından https://example.com/mysite/ base.

Bu kodu çalıştırmayı deneyin:

$html->link('my account', 
    array('base' => 'https://example.com/mysite/', 'controller' => 'users'));