fork download
  1. <?php
  2.  
  3. function is_user_logged_in() { return false; }
  4. function the_ID() { return 10; }
  5. $_GET['job_fav'] = 10;
  6. define('COOKIE_PREFIX', 'test-');
  7. $job_sector_html = '';
  8. $html = '';
  9.  
  10. if (!is_user_logged_in()) {
  11.  
  12. $id = the_ID();
  13. $favouriteID = $_GET['job_fav'];
  14. $cookieURL = '/jobs/?job_fav=' . $id;
  15.  
  16. $currentIDs = []; // Storage Array.
  17.  
  18.  
  19. // If the user has the $_COOKIE set already.
  20. if (isset($_COOKIE[COOKIE_PREFIX . 'job_fav'])) {
  21. $currentIDs = explode('|', $_COOKIE[COOKIE_PREFIX . 'job_fav']);
  22.  
  23. // Append the new ID.
  24. $currentIDs[] = $favouriteID;
  25. setcookie(COOKIE_PREFIX . 'job_fav', implode('|', $currentIDs));
  26. header('Location: ' . $cookieURL);
  27. }
  28.  
  29. $currentIDs[] = $favouriteID;
  30. setcookie(COOKIE_PREFIX . 'job_fav', implode('|', $currentIDs));
  31.  
  32. // Build up the HTML.
  33. $html .= '<a href="/jobs/?job_fav=' . htmlspecialchars($id) . '">';
  34. $html .= '<div class="job-single-favourite icon-' . htmlspecialchars($job_sector_html);
  35. if (in_array($id, $currentIDs)) {
  36. $html .= ' starred-job';
  37. }
  38. $html .= '">';
  39. $html .= '</div>hey</a>';
  40.  
  41. echo $html;
  42. }
Success #stdin #stdout 0.03s 52480KB
stdin
Standard input is empty
stdout
<a href="/jobs/?job_fav=10"><div class="job-single-favourite icon- starred-job"></div>hey</a>