从长对象

时间:2017-08-30 09:04:35

标签: php arrays string object cakephp

解决此问题的唯一方法是从HTTP_REFERER中读取并获取变量。这是我试图读取的打印对象,并从中获取可用的变量:

  

App \ Controller \ EventsController对象([name] => Events [helpers]   => Array()[request] => Cake \ Http \ ServerRequest对象([params] =>数组([controller] =>事件[action] => eventblock [pass] =>数组   ()[plugin] => [_matchedRoute] => /:controller /:action / * [isAjax] =>   1)[数据] => Array()[query] => Array()[cookies] =>数组()   [_environment:protected] =>数组([REDIRECT_REDIRECT_TMP] =>   / Applications / AMPPS / tmp [REDIRECT_REDIRECT_STATUS] => 200   [REDIRECT_TMP] => / Applications / AMPPS / tmp [REDIRECT_STATUS] => 200   [TMP] => / Applications / AMPPS / tmp [HTTP_HOST] =>本地主机   [HTTP_CONNECTION] => keep-alive [HTTP_PRAGMA] =>无缓存   [HTTP_CACHE_CONTROL] => no-cache [HTTP_ACCEPT] => /   [HTTP_X_REQUESTED_WITH] => XMLHttpRequest [HTTP_USER_AGENT] =>   Mozilla / 5.0(Macintosh; Intel Mac OS X 10_11_2)AppleWebKit / 537.36   (KHTML,与Gecko一样)Chrome / 60.0.3112.113 Safari / 537.36 [HTTP_REFERER]   => http://betpool/events/view/65506 [HTTP_ACCEPT_ENCODING] => gzip,deflate,br [HTTP_ACCEPT_LANGUAGE] =>   de-de,de; q = 0.8,en-US; q = 0.6,en; q = 0.4 [PATH] =>   / usr / bin:/ bin:/ usr / sbin:/ sbin [SERVER_SIGNATURE] => [SERVER_SOFTWARE]   => Apache / 2.4.25(Unix)PHP / 7.0.16 mod_wsgi / 4.5.11 Python / 3.6 OpenSSL / 1.0.1p [SERVER_NAME] => localhost [SERVER_ADDR] => :: 1   [SERVER_PORT] => 80 [REMOTE_ADDR] => :: 1 [DOCUMENT_ROOT] =>   / Applications / AMPPS / www [REQUEST_SCHEME] => http [CONTEXT_PREFIX] =>   [CONTEXT_DOCUMENT_ROOT] => / Applications / AMPPS / www [SERVER_ADMIN] =>   admin @ localhost [SCRIPT_FILENAME] =>   /Applications/AMPPS/www/betpool/online/betpool/webroot/index.php   [REMOTE_PORT] => 51901 [REDIRECT_URL] =>   / betpool / online / betpool / webroot / events / eventblock [GATEWAY_INTERFACE]   => CGI / 1.1 [SERVER_PROTOCOL] => HTTP / 1.1 [REQUEST_METHOD] =>获取[QUERY_STRING] => [REQUEST_URI] =>   / betpool / online / betpool / events / eventblock [SCRIPT_NAME] =>   /betpool/online/betpool/webroot/index.php [PHP_SELF] =>   /betpool/online/betpool/webroot/index.php [REQUEST_TIME_FLOAT] =>   1504083056.053 [REQUEST_TIME] => 1504083056 [ORIGINAL_REQUEST_METHOD] => GET [HTTPS] => )[url] => events / eventblock [base] => / betpool / online / betpool [webroot] => / betpool / online / betpool / [here]   => / betpool / online / betpool / events / eventblock [trustProxy] => [_input:protected] => [_detectorCache:protected] =>数组([ajax] =>   1 [get] => 1 [head] => [options] => )[stream:protected] =>   Zend \ Diactoros \ PhpInputStream对象(   [cache:Zend \ Diactoros \ PhpInputStream:private] =>   [reachEof:Zend \ Diactoros \ PhpInputStream:private] =>   [resource:protected] =>资源ID#87 [stream:protected] =>   php:// input)[uri:protected] => Zend \ Diactoros \ Uri Object(   [allowedSchemes:protected] =>数组([http] => 80 [https] => 443)   [方案:Zend \ Diactoros \ Uri:私人] => HTTP   [userInfo:Zend \ Diactoros \ Uri:private] =>   [主持人:Zend \ Diactoros \ Uri:私人] =>本地主机   [port:Zend \ Diactoros \ Uri:private] => [路径:Zend的\ Diactoros \乌里:私人]   => / events / eventblock [query:Zend \ Diactoros \ Uri:private] => [片段:Zend \ Diactoros \ Uri:私人] =>   [uriString:Zend \ Diactoros \ Uri:private] => [base] =>   / betpool / online / betpool [webroot] => / betpool / online / betpool /)   [session:protected] => Cake \ Network \ Session对象(   [_engine:protected] => [_started:protected] => [_lifetime:保护]   => 1440 [_isCLI:protected] => )[attributes:protected] => Array()[emulatedAttributes:protected] =>数组([0] =>会话[1] =>   webroot [2] => base [3] => params)[uploadedFiles:protected] =>排列   ()[protocol:protected] => ....

是否可以从此代码中获取http://betpool/events/view/65506,是否可以将其存储在php var中?

1 个答案:

答案 0 :(得分:0)

你没有提到你正在使用哪个版本的Cakephp,但是Cakephp有一个处理请求的内置机制。

请按照手册获取更多信息: https://book.cakephp.org/2.0/en/controllers/request-response.html#CakeRequest::referer

$this->request->referer()

应该返回您正在寻找的字符串。

分享您的一些代码,以获得有关此功能使用的更好指导。