PsyOps

ping.php

Mar 19th, 2014
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.96 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * @file
  5.  * Example ping script.
  6.  *
  7.  * This script is intended to be used as a starting point to copy and
  8.  * adapt to your needs.
  9.  */
  10.  
  11. define('DRUPAL_ROOT', '/path/to/drupal');
  12.  
  13. // Prevent sql injection.
  14. $timestamp = $_GET['timestamp'];
  15. if (!is_numeric($timestamp)) {
  16.   die();
  17. }
  18.  
  19. // Connect to drupal database.
  20. require_once DRUPAL_ROOT . '/sites/default/settings.php';
  21.  
  22. $creds = $databases['default']['default'];
  23. $constr = sprintf("%s:dbname=%s", $creds['driver'], $creds['database']);
  24. $db = new PDO($constr, $creds['username'], $creds['password']);
  25.  
  26. // Get count of new items.
  27. $result = $db->query("SELECT count(nid) FROM node WHERE created > $timestamp");
  28.  
  29.  
  30. // HTTP headers to prevent caching the result of this call.
  31. header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
  32. header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past (HTTP 1.0)
  33.  
  34. // JSON response.
  35. print '{"pong":"' . $result->fetchColumn() . '"}';
Advertisement
Add Comment
Please, Sign In to add comment