link.ajax.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Responses to AJAX calls
  5. */
  6. require_once '../global.inc.php';
  7. api_protect_course_script(true);
  8. $action = $_REQUEST['a'];
  9. switch ($action) {
  10. case 'check_url':
  11. if (api_is_allowed_to_edit(null, true)) {
  12. $url = $_REQUEST['url'];
  13. //Check if curl is available
  14. if (!in_array('curl', get_loaded_extensions())) {
  15. echo '';
  16. exit;
  17. }
  18. // set URL and other appropriate options
  19. $defaults = array(
  20. CURLOPT_URL => $url,
  21. CURLOPT_HEADER => 0,
  22. CURLOPT_RETURNTRANSFER => TRUE,
  23. CURLOPT_TIMEOUT => 4
  24. );
  25. //create a new cURL resource
  26. $ch = curl_init();
  27. curl_setopt_array($ch, $defaults);
  28. // grab URL and pass it to the browser
  29. $result = curl_exec($ch);
  30. // close cURL resource, and free up system resources
  31. curl_close($ch);
  32. if($result) {
  33. echo Display::return_icon('accept.png', get_lang('Ok'));
  34. } else {
  35. echo Display::return_icon('wrong.gif', get_lang('Wrong'));
  36. }
  37. }
  38. break;
  39. default:
  40. echo '';
  41. }
  42. exit;