Issue
My only option to solve this problem is to read and get the variable out of the HTTP_REFERER. Here is the printed object I am trying to read and get a usable variable out of:
App\Controller\EventsController Object ( [name] => Events [helpers] => Array ( ) [request] => Cake\Http\ServerRequest Object ( [params] => Array ( [controller] => Events [action] => eventblock [pass] => Array ( ) [plugin] => [_matchedRoute] => /:controller/:action/* [isAjax] => 1 ) [data] => Array ( ) [query] => Array ( ) [cookies] => Array ( ) [_environment:protected] => Array ( [REDIRECT_REDIRECT_TMP] => /Applications/AMPPS/tmp [REDIRECT_REDIRECT_STATUS] => 200 [REDIRECT_TMP] => /Applications/AMPPS/tmp [REDIRECT_STATUS] => 200 [TMP] => /Applications/AMPPS/tmp [HTTP_HOST] => localhost [HTTP_CONNECTION] => keep-alive [HTTP_PRAGMA] => no-cache [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, like 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] => GET [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] => Array ( [ajax] => 1 [get] => 1 [head] => [options] => ) [stream:protected] => Zend\Diactoros\PhpInputStream Object ( [cache:Zend\Diactoros\PhpInputStream:private] => [reachedEof:Zend\Diactoros\PhpInputStream:private] => [resource:protected] => Resource id #87 [stream:protected] => php://input ) [uri:protected] => Zend\Diactoros\Uri Object ( [allowedSchemes:protected] => Array ( [http] => 80 [https] => 443 ) [scheme:Zend\Diactoros\Uri:private] => http [userInfo:Zend\Diactoros\Uri:private] => [host:Zend\Diactoros\Uri:private] => localhost [port:Zend\Diactoros\Uri:private] => [path:Zend\Diactoros\Uri:private] => /events/eventblock [query:Zend\Diactoros\Uri:private] => [fragment:Zend\Diactoros\Uri:private] => [uriString:Zend\Diactoros\Uri:private] => [base] => /betpool/online/betpool [webroot] => /betpool/online/betpool/ ) [session:protected] => Cake\Network\Session Object ( [_engine:protected] => [_started:protected] => [_lifetime:protected] => 1440 [_isCLI:protected] => ) [attributes:protected] => Array ( ) [emulatedAttributes:protected] => Array ( [0] => session [1] => webroot [2] => base [3] => params ) [uploadedFiles:protected] => Array ( ) [protocol:protected] => ....
Is it possible to get http://betpool/events/view/65506
out of this code and if, is it possible to store this in a php var?
Solution
You haven't mention which version of Cakephp you're using but Cakephp has a built-in mechanism for handling requests.
Follow the manual for more information: https://book.cakephp.org/2.0/en/controllers/request-response.html#CakeRequest::referer
$this->request->referer()
should return the string you're looking for.
Share some of your code for better guidance regarding the usage of this function.
Answered By - Ofir Baruch
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.