Running undisclosed PHP in a Drupal template?

I need to run a PHP code snippet in a Drupal template and prevent its caching. The PHP sniff sniffs the cookie, and if it is found, a cookie based message is returned.

t

if(isset($_GET['key'])) { 
    $cookievalue = $_GET['key']; 
}

if(isset($_COOKIE['cookname'])) { 
    $cookievalue = $_COOKIE['cookname']; 
}

switch ($cookievalue) { 
    case hmm01: echo "abc"; 
    break; 
    case hmm02: echo "def";
    break; 
    case hmm03: echo "ghi"; 
    break; 
    default: echo "hello"; 
}

Drupal currently displays messages randomly depending on when the page was first cached and based on the cookie used at that time.

I don’t see much information on how I can do this - it seems that you should disable the cache for the page, and not run php code without access.

Can the community learn how to use the right technique for Drupal and PHP templates based on the information I posted, or direct me to a guide or tutorial that may be useful for my situation?

+3
1

, Drupal , , , , .

, , js Ajax. Drupal , . js , . , , , .

Edit:

, , , . Drupal , . hook_block

+1

Source: https://habr.com/ru/post/1738727/


All Articles