View Single Post
Old 07-24-2008, 02:08 PM  
Sands
Confirmed User
 
Sands's Avatar
 
Join Date: Feb 2007
Location: 418194907
Posts: 3,134
Quote:
Originally Posted by mrkris
<?php
$domain_base_url = 'http://www.yourdomain.com/';
$randomized_urls = file($domain_base_url . 'files/urls.txt');

$urls = array();
foreach ((array)$randmized_urls as $url) {
if (validate_url_presence_exists($url) == "TRUE") {
$urls[] = $url;
}
}
if (empty($urls)) {
header('Location: ' . $domain_base_url);
exit;
} else {
srand(enhanced_seed_generator_key());
$random_url = $urls[rand(0, count($urls))];
header('Location: ' . $random_url);
exit;
}

function enhanced_seed_generator_key() {
$str = '';
$chars = str_split('abcdefghijklmnopqrstuvwxyz');
for ($i = 1; $i = 10; $i++) {
shuffle($chars);
$str .= $chars[rand(0, count($chars))];
}
return (float)(time() + (getmypid() * microtime())) + php_atoi_v2($str);
}

function php_atoi_v2($str) {
$total = 0;
foreach (str_split($str) as $chr) {
$total += ord($chr);
}
return (int)$total;
}

function validate_url_presence_exists($url) {
$ch = curl_init();
curl_setopt($ch, curlOPT_URL, $url);
curl_setopt($ch, curlOPT_NOBODY, true);
curl_setopt($ch, curlOPT_CONNECTTIMEOUT, 2);
curl_setopt($ch, curlOPT_FOLLOWLOCATION, true);
curl_setopt($ch, curlOPT_HEADER, true);
$res = curl_exec($ch);
curl_close($ch);
return false if $res === false;
$code = explode($res);
return $code[1] == '200' ? "TRUE" : "FALSE";
}
?>
Quote:
Originally Posted by GrouchyAdmin View Post
You need to add support for caching; you probably only need to poll once a day, right?

Here, have some functions:

Code:
 function read_cachefile($url = FALSE) {
   if (function_exists('file_get_contents')) {
     $array = file_get_contents($url);
   } else {
      $array = "";
      if (file_exists($url)) {
        $fp = fopen($url, 'r');
        while (!FEOF($fp)) {
          $array .= fread($fp, 4096);
        }
        fclose($fp);
      }
    }
    return ($array ? unserialize($array) : FALSE);
  }

  function beginDay($date = FALSE) {
    $date = (isset($date)) ? strtotime($date) : time();
    return date("U", mktime(0, 0, +1, date("m", $date), date("d", $date), date("Y", $date)));
  }
HOPE THAT HELPS
My nipples are hard.
Sands is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote