0

Im using cakephp to make plugin, so i did apiController to return data (updated) from data base.. I m calling the function as :

$token = hash("sha256","appliTest".strtotime(date('Y-m-d')));
 $date = strtotime(date('Y-m-d'));
     $api_data = file_get_contents("http://local.mywebsite.com/appliTest/
     api/getData?token=".$token);

and in that function getData in apiController i did this :

if((isset($this->params["url"]["token"])) 
&&($this->params["url"]["token"]==hash("sha256","appliTest".strtotime(date('Y-m-d'))))){
die("ok");
}

thanks for helping ...

Fredj
  • 59
  • 2
  • 9

1 Answers1

0

I am writing this answer while under the assumption that you're using CakePHP 2.0.

The Request and Response documentation states that you can get the query from the URL by calling $this->request->query['page'];.

Example:

// URL is /posts/index?page=1&sort=title
$page = $this->request->query['page'];

In this example $post will contain 1. The documentation also states that:

You can either directly access the $query property, or you can use CakeRequest::query() to read the URL query array in an error-free manner. Any keys that do not exist will return null:

$foo = $this->request->query('value_that_does_not_exist');
// $foo === null

This means if the query you're trying to fetch does not exist, you'll get an null in stead of an error message if not caught properly.

So to get your token you'd have to do something along the lines of:

<?php

$token = $this->request->data('token');

if($token != null && ($token == hash("sha256","appliTest".strtotime(date('Y-m-d'))))){
    die("ok");
}
Community
  • 1
  • 1
Sevvlor
  • 560
  • 1
  • 7
  • 24
  • thank's for answering, but the problem still the same ! – Fredj Apr 04 '17 at 13:10
  • Is it possible that the problem resides somewhere else? Perhaps is the web server running CakePHP stripping the query string or are you placing the code in the wrong controller? Perhaps an incorrect URL in the part of the code thats generating the request. – Sevvlor Apr 04 '17 at 13:19
  • now it work ,I mean the token is exist and not nul but the content is not like other when i called the function ! – Fredj Apr 04 '17 at 13:28
  • the value of token is not like that in url ! – Fredj Apr 04 '17 at 13:37