我正在尝试加密CakePHP中传递的URL。我遵循了这篇文章(http://bakery.cakephp.org/articles/yuri.salame/2008/07/15/encrypting-urls#),但它不起作用。我知道这是一篇旧文章。我正在使用CakePHP 2.x
以下是显示的错误:
Notice (8): Undefined index: url [APP/webroot/index.php, line 108]
Warning (4096): Argument 1 passed to Dispatcher::dispatch() must be an instance of CakeRequest, null given, called in /home/xxx/domains/xxx.com/public_html/xxx/v3/app/webroot/index.php on line 110 and defined [CORE/Cake/Routing/Dispatcher.php, line 140]
Warning (4096): Argument 2 passed to Dispatcher::dispatch() must be an instance of CakeResponse, none given, called in /home/xxx/domains/xxx.com/public_html/xxx/v3/app/webroot/index.php on line 110 and defined [CORE/Cake/Routing/Dispatcher.php, line 140]
Notice (8): Trying to get property of non-object [CORE/Cake/Routing/Filter/AssetDispatcher.php, line 45]
我的 app / webroot / index.php 是(我只显示最后一部分):
App::uses('Dispatcher', 'Routing');
$url = do_decrypt($_REQUEST["url"]);
$Dispatcher = new Dispatcher();
$Dispatcher->dispatch($url);
$Dispatcher = new Dispatcher();
$Dispatcher->dispatch(
new CakeRequest(),
new CakeResponse()
);
答案 0 :(得分:1)
在CakePHP 2.x中更改了CakePHP附带的.htaccess
文件。它不再设置url
变量,因此在$_REQUEST
中不可用。相反,您可以使用$_SERVER['REQUEST_URI']
来获取网址。然后必须将此URL传递给CakeRequest
的构造函数。所以你的代码看起来像:
App::uses('Dispatcher', 'Routing');
$url = do_decrypt($_SERVER["REQUEST_URI"]);
$Dispatcher = new Dispatcher();
$Dispatcher->dispatch(
new CakeRequest($url),
new CakeResponse()
);